The gases are produced as a by-product of digesting certain types of food. Flatulence producing foods are typically high in starch, and include beans, yams, sweet potatoes, chickpeas, citrus rinds, chestnuts, broccoli, cabbage, yeast in breads, etc. In beans, the most notorious offenders in this regard, the problem seems to arise from starch molecules resistant to digestion: when the polysaccharides reach the intestines, intestinal bacteria feed on them, producing gas. In the case of those with lactose intolerance (ie. most non-Caucasian humans), intestinal bacteria feeding on lactose can give rise to excessive gas production. Another source of excessive gas production in the stomach is stress. Stressful situations can cause the stomach to produce gas. Also, not only does tight clothing cause a gassy stomach to be painful, it also can contribute to the production of gas.
Certain spices counteract the production of intestinal gas, most notably cumin, caraway and the closely related ajwain[?], turmeric, asafoetida (hing) and kombu[?] (a Japanese culinary seaweed closely related to kelp).
Many people notice that if they reduce their intake of most refined carbohydrates such as rice, pasta, potatoes, and breads, their stomach gas production decreases significantly.
Methane is the primary gas released. Four other gases that are found in large proportion are nitrogen, hydrogen, carbon dioxide, and oxygen. As methane and hydrogen are flammable, some flatulence is as well. The gas released often has a foul odor which mainly results from sulfur compounds such as hydrogen sulfide that are the result of protein breakdown.
In many human cultures, excessive flatulence is regarded as embarrassing and impolite, even to the point of being a taboo subject; and hence a natural subject for toilet humour: see Blazing Saddles, Le Pétomane, Kangaroo Jack, and Austin Powers, among others. Flatulence can be considered humourous to some people, either due to the scent or the sounds produced. Some find humor in lighting farts, which works well due to the methane content.