what causes the body to float and sink?

like a dead person will float up but when you get into the water alive esp in deep water your body naturally sinks (dead weight) but then float back up if you move your arms and legs (thread water)

Can anyone explain in details and maybe provide another example?