what causes gas?

Source: National Institute of Diabetes and Digestive and Kidney Diseases

What causes gas?
Everyone has gas and eliminates it by burping or passing it through the rectum, commonly known as fart.
Gas in the digestive tract the esophagus, stomach, small intestine, and large intestine comes from two sources:
-- swallowed air
-- normal breakdown of certain undigested foods by harmless bacteria naturally present in the large intestine, also called the colon

Swallowed Air:
- aerophagia, or air swallowing, is a common cause of gas in the stomach. Everyone swallows small amounts of air when eating and drinking. Burping or belching is the way most swallowed air leaves the stomach. The remaining gas moves into the small intestine, where it is partially absorbed. A small amount travels into the large intestine for release through the rectum.

Breakdown of Undigested Foods:
- the body does not digest and absorb some carbohydrates in the small intestine because of a shortage or absence of certain enzymes that aid digestion. This undigested food then passes from the small intestine into the large intestine, where normal, harmless bacteria break down the food, producing hydrogen, carbon dioxide, and, in about one-third of all people, methane. Eventually these gases exit through the rectum. The unpleasant odor of flatulence, the gas that passes through the rectum, comes from bacteria in the large intestine that release small amounts of gases containing sulfur.

Which foods cause gas?
Most foods that contain carbohydrates can cause gas. By contrast, fats and proteins cause little gas.

The sugars that cause gas are raffinose, fructose, lactose, and sorbitol.
Raffinose - beans contain large amounts of this complex sugar.
Fructose - it is naturally present in onions, artichokes, pears, and wheat. It is also used as a sweetener in some soft drinks and fruit drinks.
Lactose - it is the natural sugar in milk. It is also found in milk products such as cheese and ice cream, and in processed foods such as bread, cereal, and salad dressing.
Sorbitol - it is a sugar found naturally in fruits, including apples, pears, peaches, and prunes. It is also used as an artificial sweetener in many dietetic foods and sugar-free candies and gums.

Most starches, including potatoes, corn, pasta, and wheat, produce gas as they are broken down in the large intestine. Rice is the only starch that does not cause gas.

Many foods contain soluble and insoluble fiber. Soluble fiber dissolves easily in water and takes on a soft, gel-like texture in the intestines. Found in oat bran, beans, peas, and most fruits. Soluble fiber is not broken down until it reaches the large intestine, where digestion causes gas.
Insoluble fiber, on the other hand, passes essentially unchanged through the intestines and produces little gas. Wheat bran and some vegetables contain this kind of fiber.