A high-fat, high-sugar diet does more than pump calories into your body. It also alters the composition of bacteria in your intestines, making it easier to gain weight and harder to lose it, research in mice suggests. And the changeover can happen in as little as 24 hours, according to a report Wednesday in the new journal Science Translational Medicine.

Many factors play a role in the propensity to gain weight, including genetics, physical activity and the environment, as well as food choices. But a growing body of evidence, much of it accumulated by Dr. Jeffrey I. Gordon of Washington University in St. Louis, shows that bacteria in the gut also play a key role.

Humans need such bacteria to help convert otherwise indigestible foods into digestible form.

Ninety percent of the bacteria fall into two major divisions, or phyla: the Firmicutes and the Bacteroidetes. Previous research had shown that obese mice had higher levels of Firmicutes, and lean ones had more Bacteroidetes.

Analyzing the genomes of the bacteria, Gordon and graduate student Peter Turnbaugh concluded that the Firmicutes were more efficient at digesting food that the body can’t.

Animals that have a higher proportion of Firmicutes convert a higher proportion of food into calories that can be absorbed by the body, making it easier to gain weight.

When the researchers transferred bacteria from obese mice into so-called gnotobiotic mice, which were raised in a sterile environment and had no bacteria in their guts, the mice gained more weight than did those receiving a similar amount of bacteria from lean mice, even though they were fed the same diet.

Gordon and Turnbaugh found that they could transfer bacteria from human intestines into gnotobiotic mice, which were fed a low-fat, plant-rich diet in the weeks before the bacteria were transplanted and for a month afterward.

After the bacteria were transplanted from a lean human donor, the colonies in the mice had a high proportion of Bacteroidetes and a low proportion of Firmicutes. But within 24 hours after the mice were switched to a high-sugar, high-fat diet, the proportions of the two phyla were reversed.

With time, the mice also grew fatter than their littermates who did not receive the human bacteria.