Fireflies produce light in a similar way to how a glowstick works. The light results from a chemical reaction, or chemiluminescence. When a light-producing chemical reaction occurs within a living organism, we call this property bioluminescence. Most bioluminescent organisms live in marine environments, but fireflies are among the terrestrial creatures capable of producing light.
If you look closely at an adult firefly, you'll see that the last two or three abdominal segments appear different than the other segments. These segments comprise the light-producing organ, a remarkably efficient structure that produces light without losing heat energy.
In fireflies, the chemical reaction that causes them to glow depends on an enzyme called luciferase. Lucifer comes from the Latin lucis, meaning light, and ferre, meaning to carry. Luciferase is literally, then, the enzyme that brings light. Firefly bioluminescence requires the presence of calcium, adenosine triphosphate (ATP), the chemical luciferan, and the enzyme luciferase within the light organ. When oxygen is introduced to this combination of chemical ingredients, it triggers a reaction that produces light.
Scientists recently discovered that nitric oxide plays a key role in allowing oxygen to enter the firefly's light organ and initiate the reaction. In the absence of nitric oxide, oxygen molecules bind to the mitochondria on the surface of light organ cells, and can't enter the light organ and trigger the reaction. So, no light can be produced. When present, nitric oxide binds to the mitochondria instead, allowing the oxygen to enter the organ, combined with the other chemicals, and generate light.
Light-producing fireflies flash in a pattern and color that is unique to their species, and these flash patterns can be used to identify them. Learning to recognize the firefly species in your area requires knowledge of the length, number, and rhythm of their flashes; the interval of time between their flashes; the color of light they produce; their preferred flight patterns; and the time of night when they typically flash.
The rate of a firefly's flash pattern is controlled by the release of ATP during the chemical reaction. The color (or frequency) of the light produced is likely influenced by pH. A firefly's flash rate will also vary with the temperature. Lower temperatures result in slower flash rates.