It's a fact that people experience flatulance on average of 14 times per day. Swallowing air can be a cause or it can be a form of bacteria, most likey in the colon. For some people certain foods cause flatulance, like fried foods and spicey foods.
Yeah answer number one is good. But as far as the farting goes, yeah it is almost always due to bacteria that live in our lower intestines in a symbiotic relationship with us. They eat and break-down certain parts of the food we eat, cellulose for one in which we are unable to digest ourselves, and then they produce gas as a by-product of the chemical reaction they cause. The gas builds up and then we fart it out.
I'm just answering based on memory of past education, the link from answer #1 I'm sure will give you more specifics if you are interested. And the bad smell usually associated with farts is usually almost always caused by methane gas (if memory serves). And like someone said above, certain beans create a lot of methane after those little bacterias get to them, and that why some people fart a lot after eating a lot of beans. Methane is also flammable, that's why you may have see on TV or movies (or in real life), people lighting their farts on fire, lol.