Humans don’t spontaneously combust, but manure does. A stable full of manure caught fire last week in Throop, New York, leaving the town smelling … unpleasant. The horses aren’t to blame, though. Microbes are.

Manure is a bacterial party. It accumulates billions of microbes as it wends through the digestive system, and even more once it lands outside. Those bacteria consume organic material in the manure and release heat—lots of heat, in the case of the large compost piles that farmers shovel manure into. The accumulated heat kills harmful bacteria like E. coli, leaving nutrient-rich fertilizer free of pathogens.

Or it erupts into fire like in Throop, where residents smelled burning horse manure long before they saw it. It started in a barn storing the stuff and almost ignited a valley of dead trees and dry brush before three fire departments put it out. Manure fires are more common than you might think, though they tend to be small. There are exceptions, though. A manure fire in Southern California burned 6,000 acres in 2009, and a 2,000 ton pile of manure in Nebraska burned for three months in 2005.

In each of those fires, the accumulated heat within a manure pile didn’t kill all the bacteria. Microbes sometimes survive temperatures of several hundred degrees. Davis Hill, who works on agricultural safety and health at Penn State, has investigated some poultry manure fires like this. “We were seeing temperatures of probably five or six hundred degrees in certain spots,” he says. Other kinds of manure can combust at far lower temperatures. That’s why Rick Koelsch, a livestock and bioenvironmental engineer at the University of Nebraska, recommends tearing apart a manure pile if the core temperature exceeds 180° Fahrenheit.

Breaking up a pile exposes the hot inner core to cooler outside air. In the winter, this can quickly extinguish smoldering manure. But in the summer, farmers must be more careful. “If the air temperature is hot,” Koelsch says, “the heat dissipates more slowly.” That’s how you get a conflagration of caca.

Moisture content also determines how hot a manure pile can get. Too much moisture drowns the bacteria before they generate much heat. Too little also kills them. When it’s just right, Koelsch says, “it can raise that temperature to a point where you could get combustion before the bacteria die off.”

And then there are air pockets. “This horse manure probably has straw in it,” Hill says. “That straw is probably allowing air particles to be trapped inside, and it’s allowing the temperatures to go a little hotter than it would normally go.” The ideal amount of air provides enough oxygen to sustain the bacteria as they heat the pile. But it also could provide enough oxygen to sustain a fire if the temperature gets too high.

The right—or wrong–combination of temperature, moisture, and air can create a pile that heats rapidly and combusts spontaneously before farmers can check the temperature.

Farmers can avoid fires by managing the size of their piles. Koelsch suggests keeping a manure pile less than 5 feet deep, because they dissipate heat more efficiently than large piles. (See: the square-cube law). Occasionally turning the pile helps, too. Bringing stuff from the surface into the middle promotes decomposition and releases built-up heat.

In one article, we’ve hit on microbiology, agricultural sciences, ecology, and thermodynamics. Not bad for flaming piles of poop.