Bioluminescent animals can be found in at least half a dozen animal phyla. This includes bioluminescent cnidarians (jellyfish, coral, and sea-pens), ctenophores ("comb jellies"), arthropods (fireflies, glow worms, certain fungus gnats, millipedes, and centipedes), certain annelids, one species of snail, marine molluscs including certain clams, nudibranchs, octopuses, and squids, various fish, some brittle stars, a group of small crustaceans, all krill, 65 species of mushrooms, protists called dinoflagellates, and a large family of bioluminescent bacteria. The last three aren't actually bioluminescent animals, but they are bioluminescent organisms.
Bioluminescence occurs in certain animals where chemical energy (in the form of ATP) is converted into light energy, usually peaking around one portion of the spectrum, making it one color. Green is by far the most common color used by terrestrial bioluminescent animals, while blue is the favored color among bioluminescent animals in the sea. Every color on the spectrum has a bioluminescent animal or protein associated with it, but most colors are quite rare. The difference in favored colors on the land and sea exists because different colors stand out in each environment, and the visual systems of animals in each environment are tuned to the local colors.
There are five accepted theories on why bioluminescent animals exist. These are that bioluminescence can perform the functions of camouflage, attraction (of prey, predators of would-be predators, and mates), repulsion by way of confusion, communication between bioluminescent bacteria (quorum sensing), and rarely, the illumination of prey (used by the Black Dragonfish). It can be hard to explain why certain organisms are bioluminescent, while with others, the reasons may be obvious.
For instance, in some species, like fireflies, bioluminescence is so integrated with the organism that it is an integral part of its lifestyle -- firefly larvae use it to repel predators, while adults use it to attract prey and signal to mates. Turn on a light bulb in an insect-infested area and you'll see the benefit of luminescence to attracting prey. Fireflies are extremely efficient at converting chemical energy into light -- they do it with an efficiency of 90%. In contrast, a typical incandescent light bulb is only 10% efficient.
Another common group of bioluminescent organisms are bioluminescent fungi. These glow green to attract nocturnal animals to aid in spore dispersal.