Beer fermentation is the metabolic conversion of malt and adjunct sugars to alcohol, acid, and CO2 using yeast or bacteria. As yeast and bacteria convert the wort sugars, approximately equal amounts of carbon dioxide and alcohol are produced. The alcohol being produced by the yeast is less dense than the sugars and water the yeast is metabolizing, so the gravity of the fermenting beer drops while fermentation continues to occur.
The two predominant types of fermentation are top fermenting which is used for ales, and bottom fermenting which is typical for lagers. The time frame for a fermentation to complete is dependent on a great many factors, just a few of them include the types of sugars that the wort is composed of, the amount of sugar in the wort (original gravity), the type of yeast and or bacteria used, the amount of yeast and or bacteria used, the health of the yeast and or bacteria, and temperature the fermentation occurs at. Most fermentations will take approximately two to six weeks to complete, but some may take upwards of a year before the beer is considered ready.
Below is a photo of beer during primary fermentation.