Go outside as the day turns to dusk, and you might just see a soft green glow rising out of the weeds. And while these flickers sometimes resemble the supernatural, we know that they actually belong to a very special beetle called the firefly.

These beetles, which are also known as lightning bugs, are a sign of summer, and many people have fond memories of catching the harmless insects in Mason jars as kids. But how many people know what puts the fire in the firefly?

It all comes down to a chemical reaction, says Sara Lewis, a firefly expert at Tufts University in Massachusetts.

You see, fireflies have a specially evolved organ on their undersides called a lantern. “And that lantern houses a couple of really, really cool chemicals,” says Lewis, who is also the author of “Silent Sparks: The Wondrous World of Fireflies.”

One is a large enzyme called luciferase. And the other is a molecule called luciferin, which is much smaller. And when these two chemicals come together, like a baseball fitting into a glove, they attract other ingredients, such as sulfur, oxygen and ATP, which is basically like raw energy. As all of these molecules come together, the tiny luciferin molecule gets really excited, says Lewis, and that causes it to give off light.

Scientists call this reaction bioluminescence (pronounced bi-o-lu-mih-neh-sens), but Lewis prefers another term.

“Bioluminescence is such a mouthful,” she says. “I think of it as living light.”

There are more than 2,000 firefly species throughout the world, and each has evolved its own unique patterns of flashes, rather like different languages. In most, the living lights are used as a way to locate and then impress potential mates. But the beacons also serve as defense.

“There’s pretty good evidence that firefly bioluminescence first evolved as a warning signal,” Lewis says.

After all, fireflies are slow in the air and would make easy pickings for a silent, super-fast flier such as a bat. But they taste terrible because they’re full of toxins that make them deadly to other animals, Lewis says, and their glowing butts seem to remind their predators of that fact.

Interestingly, the peaceful little flashers we see on a summer evening are only the very last phase in the firefly’s life cycle. Most adults live for just two weeks, Lewis says.

But firefly babies, called larvae, spend about two years underground, where they hunt snails, worms and slugs.

“They are actually voracious carnivores [or meat-eaters],” Lewis says.

What’s more, the larvae light up, too, which is why they are sometimes called glow worms.

Unfortunately, fireflies have become far less common than they used to be, thanks to a combination of habitat loss and light pollution. So the next time you see one of these insects hovering in your backyard, cut the critter a break and let it go about its business. After all, doing so might ensure that the next generation gets to fire up its living lights.