Fireflies produce a chemical reaction inside their bodies that allows them to light up. This type of light production is called bioluminescence. The method by which fireflies produce light is perhaps the best known example of bioluminescence. When oxygen combines with calcium, adenosine triphosphate (ATP) and the chemical luciferin in the presence of luciferase, a bioluminescent enzyme, light is produced. Unlike a light bulb, which produces a lot of heat in addition to light, a firefly's light is cold light, without a lot of energy being lost as heat. This is necessary because if a firefly's light-producing organ got as hot as a light bulb, the firefly would not survive the experience.
A firefly controls the beginning and end of the chemical reaction, and thus the start and stop of its light emission, by adding oxygen to the other chemicals needed to produce light. This happens in the insect's light organ. When oxygen is available, the light organ lights up, and when it is not available, the light goes out. Insects do not have lungs, but instead transport oxygen from outside the body to the interior cells within through a complex series of successively smaller tubes known as tracheoles. For a long time it was a mystery as to how some firefly species manage such a high flash rate, considering the relatively slow speed of the muscles that control oxygen transport. Researchers fairly recently learned that nitric oxide gas (the same gas that is produced by taking the drug Viagra) plays a critical role in firefly flash control. In short, when the firefly light is off," no nitric oxide is being produced. In this situation, oxygen that enters the light organ is bound to the surface of the cell's energy-producing organelles, called the mitrochondria, and is thereby not available for transport further within the light organ. The presence of nitric oxide, which binds to the mitochondria, allows oxygen to flow into the light organ where it combines with the other chemicals needed to produce the bioluminescent reaction. Because nitric oxide breaks down very quickly, as soon as the chemical is no longer being produced, the oxygen molecules are again trapped by the mitochondria and are not available for the production of light.
Fireflies appear to light up for a variety of reasons. The larvae produce short glows and are primarily active at night, even though many species are subterranean or semi-aquatic. Fireflies produce defensive steroids in their bodies that make them unpalatable to predators. Larvae use their glows as warning displays to communicate their distastefulness. As adults, many fireflies have flash patterns unique to their species and use them to identify other members of their species as well as to discriminate between members of the opposite sex. Several studies have shown that female fireflies choose mates depending upon specific male flash pattern characteristics. Higher male flash rates, as well as increased flash intensity, have been shown to be more attractive to females in two different firefly species.
The adult fireflies of some species are not luminous at all, however, and instead use pheromones to locate mates. The use of pheromones as sexual signals appears to be the ancestral condition in fireflies with the use of luminous sexual signals as being a more recent development. There are species that employ both pheromonal and luminous components in their mating systems. These species appear to be evolutionarily intermediate between the pheromone-only fireflies and flash-only fireflies.