Flatus is the name given to the combination of gases that are expelled at high-speed through the rectum. There are two main causes:
Ingested air - exogenous source of air coming through the mouth and nose. The air is also swallowed as we eat and drink. Consequently the primary gas release during flatulence is nitrogen, which is the main constituent of air.
Food - for food to be useful to our body it has to be absorbed into the bloodstream and usually this occurs through the lining of the stomach and small intestine. However, many foods contain long chain sugar molecules known as carbohydrates which cannot be absorbed. But what our bodies can't handle microbes will, and so carbohydrates pass into the colon for further processing. Here hundreds of different types of bacteria start to break them down. One of the results of this bacterial digestion is the gas that's given off as a by-product and released as flatulence.
Some of the foods which contain a large amount of indigestible carbohydrates are beans, pulses, raisins, broccoli, leeks, sweet potatoes, and turnips. Generally speaking, the more indigestible carbohydrates that are in a food stuff then the bigger the contribution to flatulence.