Beer contains certain oligosaccharides chains of two to ten sugars. Because our bodies lack enzymes needed to break these sugar chains into forms that can be metabolized, these sugars pass on to the lower intestinal tract where anaerobic bacteria feast away on them. And as they do, these bacteria produce a gas with a distinctive odor.
In the mashing process, enzymes present in the barley break down starch from the grains, producing mostly glucose, maltose, and other oligo- and polysaccharides such as sucrose, stachyose, verbascose, and raffinose. After the resulting wort is hopped and yeast is added, the smaller saccharides are fermented to produce alcohol. In general, saccharides larger than a three chain sugar are not fermentable. However, they will contribute to the caloric value as well as to the overall flavor of the beer, its ability to form a head, and ultimately, flatulence.