Everybody produces intestinal gas.
Some comes from swallowed air.
A large part is produced when bacteria in the large intestine ferment material that your own digestive enzymes did not completely break down.
Eventually that gas needs an exit.
Gut bacteria eat leftovers
Humans cannot digest every carbohydrate and fiber molecule that passes through the digestive system.
When those materials reach the large intestine, bacteria can use them as food.
As the bacteria metabolize the material, they produce gases.
Common intestinal gases include hydrogen and carbon dioxide. Some people also produce methane.
Why do farts smell?
Most of the volume of intestinal gas has little or no smell.
The odor comes from much smaller amounts of strongly scented compounds.
Some contain sulfur.
That means the chemicals causing the smell may represent only a tiny fraction of the total gas.
A little chemistry can create a very large social problem.
Why do some foods produce more gas?
Foods differ in the carbohydrates, fibers, and other compounds they contain.
People also differ in digestive enzymes and gut bacteria.
A food that causes dramatic gas in one person may barely affect another.
Beans are famous because some of their carbohydrates are not fully digested in the small intestine and become excellent bacterial food later.
Does swallowed air contribute too?
Yes.
Air swallowed while eating, drinking, chewing gum, or talking can enter the digestive tract.
Some comes back up as a burp.
Some can continue through the intestines.
How often is normal?
There is wide variation.
Passing gas every day is normal because gas production is a normal consequence of digestion and having a living community of microbes in the gut.
Sudden major changes, severe pain, persistent bloating, blood in the stool, or other concerning symptoms are different and may need medical evaluation.
Why is the timing always terrible?
Biology has no respect for meetings.
Gas moves through the intestine as muscles push digestive contents along.
Eventually pressure reaches a point where the gas passes through the rectum.
The system cares about pressure.
It does not care that the room just became completely silent.
A related explanation is Why do we burp?, which looks at another familiar effect from the same general system.
And that’s the short explanation.
Related explanations: Why do we burp?, Why does your stomach growl?, and Why is poop brown?