Everyone knows that some farts smell worse than others. Now, a team of scientists has figured out why. It turns out what you eat plays a big part in how stinky the gas your body passes is.

Farts are composed of two types of gases: odorless ones from the air we swallow and others produced by the bacteria in our guts that munch on the food we’ve eaten. One of the gases produced by bacteria is called hydrogen sulfide. It’s responsible for a fart’s rotten-egg odor. 

Researchers at Monash University in Melbourne, Australia, wanted to know how different foods affect the amount of hydrogen sulfide in the gut. “We found that the bacteria that live in our large intestine like breaking down compounds called fermentable fibers,” says C.K. Yao, who studies diets and intestinal health. Fiber is the part of plant-based foods that people’s bodies can’t digest, but it can be the perfect food for bacteria in our guts. 

If a person’s diet isn’t high in fermentable fiber but is rich in protein, like that found in meat, eggs, and dairy products, gut microbes will eat the protein instead. When bacteria eat protein, they produce a lot more hydrogen sulfide, explains Yao. 

To prevent stinky farts, Yao suggests eating protein-rich foods at the same time as those high in fermentable fiber. These foods include grainy bread, beans, pasta, and potatoes. This should keep not only your gut’s bacteria happy, but also anyone nearby if you pass gas.