When faced with pathogenic fungi, bees line their hives with more propolis — the waxy, yellow substance seen here.

When they get sick, bees raid their own "medicine cabinet," researchers have found. Specifically, when infected with fungi, they collect loads of antifungal plant extracts and coat their hives with them.

The mix of plant resins and wax that the bees usually use to line their hives, called propolis, have antifungal properties.

The new research could help beekeepers ward off fungal infection in their colonies, Michael Simone-Finstrom of North Carolina State University said in a statement. "Historically, U.S. beekeepers preferred colonies that used less of this resin, because it is sticky and can be difficult to work with," he said. "Now we know that this is a characteristic worth promoting, because it seems to offer the bees some natural defense."

The researchers studied 23 colonies, 12 of which had hives coated with "natural" amounts of resin, and 11 with the low amounts normally used in beekeeping. They then challenged the colonies with fungal and bacterial infections, and analyzed how many bees went out to fetch resin for the propolis in each hive, to see if the hive was sending out more foragers to get resin.

The researchers found that when facing a fungal threat the bees brought in 45 percent more of the waxy creation to line their hives, and physically removed fungally-infected larvae from their area. Interestingly, that means they have a better grasp of the germ theory of disease than humans did before the 19th century — things that come into contact with microbes tend to cause further infection, the researchers noted.

"The colony is willing to expend the energy and effort of its worker bees to collect these resins," Simone-Finstrom said in a statement. "So, clearly this behavior has evolved because the benefit to the colony exceeds the cost."

The bees were even aware of which fungi were harmful and which weren't. When infected with fungus that didn't cause disease, the bees didn't ramp up their propolis deposition in response.

Though this waxy substance can also defend the hive against bacteria, the bees don't seem to use it to the same advantage. The researchers saw what looked like a small increase in propolis in the hives infected with disease-causing bacteria, but the effect wasn't significant. "There was a slight increase, but it was not statistically significant," Simone-Finstrom said. "That is something we plan to follow up on."

The study was published March 29 in the journal PLoS ONE.

You can follow LiveScience staff writer Jennifer Welsh on Twitter @microbelover. Follow LiveScience for the latest in science news and discoveries on Twitter @livescience and on Facebook.