If oxygen is present, cells use glycolysis to produce ATP. To put it simply:
A single molecule of glucose splits in two producing 2 molecules of pyruvic acid. It is then followed by the Krebs Cycle and the electron transport chain. Overall, this process produces a net gain of 36 ATP molecules. However, if a cell lacks in oxygen, then this process cannot take place. That is why the cell must resort to fermentation to gain the ATP it needs to perform basic functions. In people, the type of fermentation that takes place is lactic acid fermentation. Lactic acid converts NADH to NAD+, allowing glycolysis,which does not require oxygen, to continue. Although it only produces a net gain of 2 ATP molecules the process can be helpful in providing ATP in a time of need.