It happens when there is not enough oxygen getting to the cells for respiration, in every living cell.
Anaerobic respiration is a type of respiration that does not use oxygen. It is used when there is not enough oxygen for aerobic respiration. This means that the body performs respiration without oxygen and just glucose, here is the equation: glucose ? lactic acid (+small amount of energy released). As you see, this respiration only needs glucose, but it produces lactic acid.
For example; when you exercise your body needs more oxygen, for more energy as you use up more energy when you exercise. In order to respire your body needs oxygen and so your breathing rate increases. Although, if even with you breath more, your body cannot respire enough, your cells will respire anaerobically.
When you exercise very hard you can sometimes feel your muscles begin to hurt and cramp. This is because, part of anaerobic respiration produces lactic acid as a by-product to energy. This acid, being acidic, wears away your muscles, and so it hurts.
I hope this helps you understand!