If you ever find yourself walking through a damp, dark woods at night without any flashlight, you might just witness something amazing. If you’re lucky, in the undergrowth concentrated on and around rotting logs, you’ll notice a green or blue glow.

For centuries this was called fairy fire or will-o-the-wisp and was attributed to something mystical. Aristotle thought it was a cold fire burning on the logs, and in 1555, Swedish priest and scholar Olaus Magnus wrote of luminous mushrooms on rotting wood. Knowing that the glow appears on rotting wood is one thing, but knowing how and why is another. It wasn’t until 1823 that the real source came to light and it's perhaps even more strange than the supernatural explanations.

The strange glow is foxfire, which can create a light bright enough to read by. Indeed, people have used foxfire to illuminate their homes or as makeshift torches as if it were fire. But rather than flames, it comes from bioluminescent fungus that feeds on the rotting logs and emanates a blue-green light.

It's not actually the rotting wood that grows green or blue, but rather the strands of fungus, or mycelium, that spread over the rotting wood. With some species, it's the mushroom cap itself that glows. The light is the result of a chemical reaction made while the fungus breaks down and consumes the wood.

Understand how foxfire works

In trying to understand just how fungi create their light, researchers from Krasnoyarsk, Moscow and Nagoya took a closer look at the reactions between luciferin and luciferase, the two substances needed for luminescence. By looking more closely, they knew they could crack the secret to why at least some mushroom species glow.

"The breakthrough came when the scientists were studying the hot extracts from a series of nonluminescent fungi," reports PhysOrg. "Some fractions began to glow when mixed with the enzyme-containing cold extracts from luminescent fungi. In these fractions, the researchers found luciferin precursors. The concentrations of these compounds were about 100 times as high as in luminescent species, where the luciferin precursors can't accumulate because they are constantly being consumed in the luminescence process."

The researchers identified hispidin, a fungal metabolite that can create the two enzymes needed for bioluminescence.

Why does a mushroom need to glow?

We've recently gotten closer to understanding the how, but there's still the why. There are some 71 species of mushroom that can produce light. Exactly how each species manages this remains a mystery, but so too is the reason for glowing. Why bother?

Ideas include attracting spore-dispersing arthropods, or perhaps dissuading insects that might feed on the fungus. The Cornell Mushroom Blog notes, "Illumination may also discourage negatively phototropic fungivores, especially those found in the soil (hence one explanation for why the mycelia of these species also glow)... An alternative idea is that bioluminescence is a side-product of lignin degradation: Reactions that lead to light production may generate antioxidants to protect the fungus from toxic peroxides released during lignin digestion."

A 2015 study showed that the mycelium of Neonothopanus gardneri follows the circadian rhythm, regulating levels of luciferin, reductase and luciferase (the chemical compound and enzymes that combine to produce light) to peak at night. This seems to point to purposefully attracting nocturnal insects.

The researchers used fake mushrooms lit by internal green LEDs to see if they would attract insects in the same way a bioluminescent fungus would. They found that beetles, flies, ants and other bugs were far more attracted to the glowing mushrooms than the dark traps used as a control.

"Thus, circadian control may optimize energy use for when bioluminescence is most visible, attracting insects that can in turn help in spore dispersal, thereby benefitting fungi growing under the forest canopy, where wind flow is greatly reduced," note the study authors.

The trick to seeing foxfire

So how can you experience foxfire for yourself?

Kim Coder of Gardening 123 advises, "The best way to see foxfire is in old, moist oak woods where plenty of big dead limbs and old stumps litter the ground. Foxfire can be seen in the spring as the forest floor warms. The light is so dim, many people never notice it. To see foxfire, pick a night with no moon. Keep away from areas with artificial lights and do not use a flashlight. Your eyes must be well adjusted to the dark."

The aim is to be out on a dark night, with a mild temperature and to walk in woods that are damp but not wet. Think of foxfire as Goldilocks — not too hot, not too cold, not too wet, not too dry. When conditions are just right, and you're in just the right spot with your eyes adjusted to the dark, the forest around you will glow — and it's magical.

Jaymi Heimbuch ( @jaymiheimbuch ) focuses on wildlife conservation and animal news from her home base in San Francisco.