what causes intestinal gas

Sugars

Sugars that are commonly digested poorly (maldigested) and malabsorbed are lactose, sorbitol, and fructose.

Lactose is the sugar in milk. The absence of the enzyme lactase in the lining of the intestines, which is a genetic trait, causes the maldigestion. Lactase is important because it breaks apart the lactose into its two component sugars, glucose and galactose, so that they can be absorbed.
Sorbitol is a commonly used sweetener in low calorie foods.
Fructose, primarily as high fructose corn syrup, is a commonly used sweetener in all types of candies and drinks. It also may be found in higher amounts in some fruits and vegetables.

Polysaccharides

Starches are another common source of intestinal gas. Starches are polysaccharides that are produced by plants and are composed of long chains of sugars, primarily fructose. Common sources of different types of starch include wheat, oats, potatoes, corn, and rice.

Rice is the most easily digested starch, and little undigested rice starch reaches the colon and the colonic bacteria. Accordingly, the consumption of rice produces little gas.
In contrast, some of the starches in wheat, oats, potatoes, and, to a lesser extent, corn, all may reach the colon. These starches, therefore, may result in the production of appreciable amounts of gas.
The starch in whole grains produces more gas than the starch in refined (purified) grains. Thus, more gas is formed after eating foods made with whole wheat flour than with refined wheat flour. This difference in gas production probably occurs because of the fiber (similar to a complex starch) present in the whole grain flour. Much of this fiber is removed during the processing of whole grains into refined flour.
Finally, certain fruits and vegetables, for example, beans and cabbage, also contain poorly digested starches that reach the colon and are easily converted by bacteria into gas.
Most vegetables and fruits contain cellulose, another type of polysaccharide that is not digested at all as it passes through the small intestine. However, unlike sugars and other starches, cellulose is used only very slowly by colonic bacteria. Therefore, the production of gas after the consumption of fruits and vegetables usually is not great unless the fruits and vegetables also contain sugars or polysaccharides other than cellulose.

Small amounts of air are continuously being swallowed and bacteria are constantly producing gas. Contractions of the intestinal muscles normally propel the gas through the intestines and cause the gas to be expelled. Flatulence (passing intestinal gas) prevents gas from accumulating in the intestines.

However, there are two other ways in which gas can escape the intestine besides flatulence.

First, it can be absorbed across the lining of the intestine into the blood. The gas then travels in the blood and ultimately is excreted by the lungs in the breath.
Second, gas can be removed and used by certain types of bacteria within the intestine. In fact, most of the gas that is formed by bacteria in the intestines is removed by other bacteria in the intestines. (Thank goodness!)