The bubbles in beer come from carbonation. In simple terms, carbonation is the carbon dioxide (chemical formula CO2) gas in a liquid. To keep the carbon dioxide gas in the liquid, there needs to be pressure. When the pressure is released, the carbon dioxide rises to escape in the form of bubbles or carbonation. All beer leaves the brewer carbonated. Beer can be carbonated in two ways, naturally or forced.

Natural carbonation is the result of the fermentation process. CO2 and alcohol is produced during the stage when the yeast digests the sugar in the wort. Most of the carbon dioxide gas escapes during this stage, however in order for the beer to stay naturally carbonated, the brewer will seal the beer in a container just before fermentation is complete. The beer is now naturally carbonated meaning that when the pressure is released the carbon dioxide rises to escape and the bubbles are formed!

In order to force carbonation, the brewer leaves the beer to fully complete fermentation. Once this is finished, the beer is put into a sealed container and pumped with CO2 which will then be absorbed into the liquid. The forced carbonation method is commonly used for kegs. The same process applies allowing fermentation to complete and pumping carbon dioxide into the keg where the gas will be absorbed into the liquid, the beer will be fully carbonated within a few days.

More Info: en.wikipedia.org