Why does a dead body float in the water

why does a dead body float in the water.

Gas build up from decaying tissue makes the body buoyant.
A cadaver in the water starts to sink as soon as the air in its lungs is replaced with water.

Once submerged, the body stays underwater until the bacteria in the gut and chest cavity produce enough gas (i.e. methane, hydrogen sulfide, and carbon dioxide) to float it to the surface like a balloon.
At first, not all parts of the body inflate at the same amount. The torso (i.e. head and limb) which contains the most bacteria, bloats more than the head and limbs. The most buoyant body parts rise first, leaving the head and limbs to drag behind the chest and abdomen.

Since arms, legs, and the head can only drape forward from the body, corpses tend to rotate such that the torso floats facedown, with arms and legs hanging beneath it.
Thus the decomposed body increases in volume weight to displace more water to float.