At this very moment, trillions of microbes are making themselves quite at home in your intestines. That’s a good thing, because that community of microbes—your ­microbiome—is key to good health. And the most important factor for a healthy microbiome is what you eat.

Here’s how it works: A well-balanced microbiome is chock-full of bacteria that produce certain short-chain fatty acids that positively influence health. These include acetate, propionate and, especially, butyrate—highly biologically active compounds that support gut health, blood sugar regulation, optimal blood fat levels, appetite control and immunity. They also cross the blood-brain barrier and so influence your mood. A healthy microbiome protects against obesity, diabetes, heart disease, certain autoimmune diseases and depression.

Those good-for-you bugs need nourishment, primarily fiber that stays ­undigested until it reaches the intestines. But the typical Western diet—high in animal protein and fat while low in fiber—effectively starves the microbiome. The solution isn’t to just eat more fiber or even more fruits and vegetables—certain foods promote a healthy microbiome in powerful, specific ways. They work in different ways, so eating a bountiful variety is best. Start by saying “yes” to these foods…

Walnuts

People who eat walnuts have more favorable cholesterol levels, as well as less diabetes, than people who rarely eat them. Why? One key reason: Eating a handful of walnuts each day—about one-third cup, or 16 walnut halves (about 215 calories)—can change the microbiome in a good way by increasing the bacteria species that generate butyrate. Other nuts that support a healthy microbiome include almonds, cashews, pistachios, hazelnuts and pecans.

Ghee

Ghee is a type of clarified butter, originally from India, that is simmered and allowed to caramelize before the milk solids are removed. What’s left is ­flavorful and aromatic butter fat without dairy proteins but with high levels of short-chain fatty acids—including ­butyrate. The flavor is concentrated, so a little goes a long way. One tablespoon a day (about 110 calories) is fine. Ghee is used in cooking and as a condiment.

FOS Foods

Fructooligosaccharides (FOS) are complex sugars that generally pass ­undigested through your digestive system until intestinal microbes break them down. FOS are the perfect diet for certain butyrate-producing bacteria. In animal studies, just two weeks on a high-FOS diet significantly increased butyrate production. FOS are found in many everyday foods including ­bananas, onions, leeks, garlic, asparagus, ­jicama and Jerusalem artichoke.

Caveat: For some people, FOS-rich foods are hard to digest and can cause gastrointestinal trouble. See “When Gut-Friendly Foods Are Bad for You,” below.

Polyphenol-Rich Food and Drink

The powerful antioxidants called polyphenols found in tea, coffee, berries, grapes, cocoa and certain vegetables (including artichokes, olives and asparagus) are strongly associated with the prevention of diabetes and heart disease. Credit the microbiome, at least in part—90% or more of polyphenols are metabolized by microbes, and they increase levels of the protective bacteria Bifidobacteria and Lactobacillus. Examples…

Olive oil. In studies, the microbiomes of animals fed olive oil had higher levels of four bacteria that are known to reduce insulin levels (associated with diabetes prevention) and increase levels of leptin, a hormone that helps control appetite.

Cocoa. Dark chocolate and cocoa powder are rich in flavanols, a type of antioxidant. In a study at University of Reading in the UK, adults who followed a diet rich in cocoa flavanols had an increase in healthful Bifidobacteria and Lactobacilli populations. My recommendation: Add two or three tablespoons of raw cacao powder to a smoothie a few times a week…or bake with it.

Fermented foods. Yogurt is made when friendly bacteria, usually Lactobacillus bulgaricus and Streptococcus thermophilus, are added to milk. Sauerkraut and kimchi (a salty Korean side dish) are made by allowing beneficial bacteria to digest the natural sugars in cabbage leaves. Other gut-friendly fermented foods include sourdough bread, certain natural cheeses (see below), olives, soy sauce, miso and tempeh. Fermented foods not only contain very high numbers of healthful microbes, but these good-for-you bacteria are particularly likely to survive the passage through the digestive tract—where they can thrive.

Tip: You already know that yogurt has health benefits, but don’t neglect cheese. In one study at University of Copenhagen in Denmark, healthy volunteers produced more butyrate when they included cheese in their diets. Best cheeses for your gut bacteria: Fresh mozzarella, aged Parmigiano, Camembert and raw-milk cheeses.

Foods to Avoid

Eating good-for-your-gut foods isn’t enough. Certain eating patterns, as well as common additives used by the food industry, can throw a monkey wrench into your microbiome. Be wary of…

Emulsifiers. Animal studies show that the microbiomes of mice fed ­diets with relatively low levels of ­emulsifiers—chemicals added to stabilize processed foods—were less robust than microbiomes of mice that weren’t fed emulsifiers. Even more concerning: Certain common emulsifiers have been found to chip away at the colon’s mucous membrane, which is nature’s way of keeping microbes inside the gut so they don’t enter the bloodstream where they can do harm. Avoid: Carboxymethylcellulose (aka cellulose gum, or CMC) and polysorbate-80. You also may want to avoid foods that contain the common emulsifier carrageenan, which can irritate the intestinal wall.

Artificial sweeteners. Sucralose, aspartame and saccharin all have been shown to disrupt the balance and diversity of gut microbiomes. Example: Mice fed sucralose for six months had higher levels of bacteria that promote inflammation. It’s also wise to avoid sugar alcohols such as xylitol, which can cause stomach distress in many people. Fine to use: Monkfruit sweetener or stevia.

Bottom line: The changes to the microbiome from what you eat may occur quickly, within 24 hours, but they don’t last long. Making good diet choices each day is your best strategy to keep your microbiome—and you—healthy.

When Gut-Friendly Foods Are Bad for You

Here’s a dilemma—some foods that promote a healthy microbiome can cause gastrointestinal distress for certain people. Solution: Heal the gut first, then slowly introduce these foods to see if they can be ­tolerated.

Example: FODMAP is an acronym for “fermentable oligosaccharides, disaccharides, monosaccharides and polyols.” Many people have trouble digesting these complex molecules—especially if they have irritable bowel syndrome—and restricting them often leads to symptom relief. But fructooligosaccharides (FOS) in particular help feed a healthy microbiome. Cutting out FODMAPs can reduce Bifidobacterium and other beneficial species.

Solution: If you need a low-­FODMAP diet, work with a health professional such as a naturopathic physician on an elimination diet. But as your symptoms improve, gradually reintroduce some foods. Adding them in slowly allows the gut flora to get used to them. You may need to stop eating onions permanently, for example—but bananas might be just fine.

A gluten-free diet poses a similar dilemma. People with celiac disease, as well as those with gluten intolerance, need to avoid wheat and other grains that contain gluten. But skipping wheat often means missing out on fiber that your microbiome needs. People on gluten-free diets have been found to have reduced levels of healthy ­Bifidobacterium and Lactobacillus and higher levels of unhealthful E. coli and Enterobacteriaceae bacteria.

Solution: If you are avoiding gluten, be sure to eat plenty of high-fiber foods, including whole grains such as oats (be sure they are certified as non-cross-contaminated with gluten), brown rice and millet. You may want to add in psyllium powder to boost your fiber intake, too. As with low-­FODMAP diets, people who start out gluten intolerant can sometimes improve their gut health enough that they can reintroduce gluten-­containing grains such as whole wheat.