The composition of fart gas is highly variable. Most of the air we swallow, especially the oxygen component, is absorbed by the body before the gas gets into the intestines. By the time the air reaches the large intestine, most of what is left is nitrogen. Chemical reactions between stomach acid and intestinal fluids may produce carbon dioxide, which is also a component of air and a product of bacterial action.
Bacteria also produce hydrogen and methane.
The longer a fart is held in, the larger the proportion of boring, inert nitrogen it contains, because the other gases tend to be absorbed into the bloodstream through the walls of the intestine. A nervous person who swallows a lot of air and who moves stuff through his digestive system rapidly may have a lot of oxygen in his farts, because his body didn't have time to absorb the oxygen. Encyclopedia Britannica offers the intriguing statement that some people's farts contain no methane. The reason for this is apparently unknown. Some researchers suspect a genetic influence, whereas others think the anomaly is due to environmental factors.