There are three main types of body compositional analysis: skinfold measurements, bioelectrical impedance analysis (BIA), and hydrostatic weighing. Skinfold measurements use a tool called a caliper to measure how thick your skin is at certain points on your body; this measurement can then be used to estimate how much fat or muscle you have based on known correlations between those two variables.
Bioelectrical impedance analysis (BIA) analysis works by sending tiny electric currents through your body and measuring how easily they pass through; based on how easily the current passes through your body (which depends on things like how hydrated you are), it can estimate how much muscle vs. fat you have.
Finally, hydrostatic weighing uses the fact that water floats based on its density (which depends on whether it contains more water or more salt) to estimate how much salt vs. water you have in your body; based on this information it can then determine how much muscle vs. fat you have as well as other useful information like your overall BMI or BMR (basal metabolic rate).