When a person's body decomposes after death, it goes through a series of stages involving different chemical changes that cause it to change its appareance. Observing these changes can help forensic scientists determine the post-mortem interval (or time since death), which is very important when it comes to investigating unnatural deaths.
The stages of decomposition are: fresh stage, bloat stage, active decay, advanced decay, and dry stage. 
The fresh stage begins right after the heart stops beating.
When the blood stops being pumped, gravity makes it settle and it changes the color of the skin where it pools, making it purple-red. This is known as livor mortis or hypostasis. 
Then, rigor mortis occurs. Rigor mortis is the stiffening of the muscles due to the disappareance of ATP (adenosin triphosphate). The proteins responsible for muscle contraction, actin and myosin, need ATP to create crossbridges and make the muscles contract, and then relax. When ATP is no longer produced by the cells, the cycle of contraction cannot be completed and the muscles remain contracted. 
Since the moment of death, the body starts losing heat to the surroundings until it reaches ambient temperature. This process is called algor mortis.
The chemical changes happening in the body affect the pH, which makes the cells release enzymes that break down the surrounding tissues in a process called autolysis. In this stage of decomposition autolysis does not cause many visible changes, other than blistering of the skin.
When the aerobic organisms in the body consume all the oxygen present, anaerobic organisms from the digestive system begin to multiply. They consume macromolecules (proteins, carbohydrates, lipids) and form acids and gases in the process of fermentation. This is known as putrefaction and it leads to the bload stage of decomposition. 
In this stage, insects start arriving at the body.
In the bloat stage, anaerobic metabolism produces gases like hydrogen sulphide, carbon dioxide, methane, ammonia, sulfur dioxide and hydrogen. These gases accumulate in the body and make it bloated. Also, they attract more insects. 
As the anaerobic metabolism continues, the pressure of the gases increases, causing the fluids in the body to escape through the natural orifices. Also, because tissues lose their integrity due to the action of the enzymes released by the cells, the pressure can be enough to break the skin and let the fluids out through those ruptures. This allows oxygen back in and allows for the development of insects and aerobic bacteria, which determines the beginning of the active decay. 
The anaerobic organisms in the intestine also transform the hemoglobin of the blood into sulfhemoglobin and other pigments. This makes the body change in color, first into green and then black. 
The next stage is active decay. This is when most of the mass loss occurs. Mass loss is caused by the activity of insects that feed on the body, and the release...