Fermentation is an organic chemical process. This process breaks down sugars into alcohol and carbon dioxide. Yeasts and some bacteria metabolize sugars into ethanol (alcohol). This process also is used in bread making and production of ethanol fuel.
C6H12O6 (glucose) → 2 C2H5OH (ethanol) + 2 CO2 (carbon dioxide)
The production of alcohol from yeast is an anaerobic process. Meaning the chemistry must occur in an oxygen depleted environment. Fermentation must occur inside a container that can release the carbon dioxide produced, while preventing oxygen from getting back in. If there is too much oxygen present cellular respiration will occur. This produces carbon dioxide and water, instead of alcohol.
Bacterial fermentation of alcohol is caused by lactobacilli. This bacteria transforms lactose into lactic acid. This is what gives Lambic beer, yogurts, and sourdough breads their signature sour flavors. The acidity also acts as a natural method of preservation.