You might not really be sure you saw what you think you saw when the first one shows up. But you stare in the direction of the flicker of light and there it is again – the first firefly of the evening. If you are in good firefly habitat, soon there are dozens, or even hundreds, of the insects flying about, flashing their mysterious signals.

Fireflies – alternatively known as lightning bugs in much of the United States – are neither flies nor bugs. They’re soft-winged beetles, related to click beetles and others. The most dramatic aspect of their biology is that they can produce light; this ability in a living organism, called bioluminescence, is relatively rare.

I’m an entomologist who does research on, and teaches about, the ecology and biology of insects. Recently, I’ve been trying to understand the diversity and ecology of fireflies in my home state of North Carolina. Fireflies are found widely across North America, including many places in the west, but they are most abundant and diverse in the eastern half of the continent, from Florida to southern Canada.

Bioluminescent beetles

Fireflies produce light in special organs in their abdomens by combining a chemical called luciferin, enzymes called luciferases, oxygen and the fuel for cellular work, ATP. Entomologists think they control their flashing by regulating how much oxygen goes to their light-producing organs.

Fireflies probably originally evolved the ability to light up as a way to ward off predators, but now they mostly use this ability to find mates. Interestingly, not all fireflies produce light; there are several species that are day-flying and apparently rely on the odors of pheromones to find each other.

Each firefly species has its own signaling system. In most North American species, the males fly around at the right height, in the right habitat and at the right time of night for their species, and flash a signal unique to their kind. The females are sitting on the ground or in vegetation, watching for males. When a female sees one making her species’ signal – and doing it well – she flashes back with a species-appropriate flash of her own. Then the two reciprocally signal as the male flies down to her. If everything goes right, they mate.

A good example is Photinus pyralis, a common backyard species often called the Big Dipper. A male flies at dusk about 3 feet off the ground. Every five seconds or so, he makes a one-second flash as he flies in the shape of a “J.” The female Photinus pyralis sits in low vegetation. If she sees a fellow she likes, she waits two seconds before making a half second flash of her own at the third second.

Some species may “call” for many hours a night, while others flash for only 20 minutes or so right at dusk. Firefly light communication can get much more complicated; some species have multiple signaling systems, and some might use their light organs for other purposes.

While most male fireflies do their own thing and flash independently of other males of the same species, there are those that synchronize their flashes when there are many others around. In North America, the two most famous species that do this are the Photinus carolinus of the Appalachian Mountains, including in Great Smoky Mountains National Park, and the Photuris frontalis that light up places like Congaree National Park in South Carolina.

In both these species, scientists think the males synchronize so everyone has a chance to look for females, and for females to signal males. These displays are spectacular, and the crush of folks wanting to see them at the most famous locations has made it necessary to conduct a lottery for permission to view them. Both species, however, occur over wide geographic ranges, and it might be possible to see them in other, less congested places.

Stinky chemical defenses

Many fireflies protect themselves from predators with chemicals called lucibufagins. These are molecules the insects synthesize from other chemicals they eat in their diet. Lucibufagins are chemically very similar to the toxins toads exude on their skins, and while they are toxic in the right doses, they are also extremely distasteful.

Birds and other predators quickly learn to avoid fireflies. I’ve watched a toad on my back porch eat a firefly and promptly spit it back out; the insect walked away, gooey but apparently unharmed. A colleague of mine once put a firefly in his mouth – and his mouth went numb for an hour!

Many other insects visually mimic fireflies in order to reap the benefit of looking like something unpleasant to eat and poisonous. Fireflies appear to produce other defensive chemicals, too, some of which may contribute to their distinctive smell.

Many Photuris fireflies can’t manufacture these defensive chemicals. So the females of these big, long-legged lightning bugs do something surprising: Once they’ve mated, they start mimicking the flashes of female Photinus and then eat the males that respond. These femme fatales go on to use the lucibufagins they acquire from ingesting their severely disappointed prey to protect themselves and their eggs from predators. They quickly transfer the chemicals to their blood, and spontaneously bleed if a predator grabs them.

No place like home

Most fireflies are habitat specialists, using woodlands, meadows and marshes. They rely on that habitat remaining undisturbed for the year or more it takes them to complete their lifecycles. These insects spend most of their lives as larvae preying on earthworms and other animals in the soil or leaf litter – most adults don’t feed at all. If that habitat is disrupted during their youth, populations can be extinguished.

Adding to this vulnerability is the fact that the females of many species – like the famous blue ghosts of the southern Appalachians and elsewhere – are wingless and can’t disperse any further than they can walk. If a population of blue ghosts is destroyed by logging or other disruption, there will be no reestablishment. Habitat destruction is therefore one of the greatest threats to fireflies. Other hazards include light pollution from artificial lights and perhaps insecticide applications for mosquito control.

There is much yet to learn about fireflies. Entomologists like me have identified about 170 or so species in North America, but it is clear that many more species occur here. Pay attention to the fireflies in your neighborhood; observe their flash patterns and behavior. Perhaps you’ll discover one of those new species.

[ Like what you’ve read? Want more? Sign up for The Conversation’s daily newsletter. ]