In general, cells in the different parts of a multicellular organism all have the same genes, although only some of these genes are expressed (translated into proteins) in any given cell. At the molecular level, highly regulated temporal and spatial changes in gene expression causes metamorphosis in all animals. Thus, in the case of a butterfly, a very simple model of metamorphosis is that one family of genes is expressed in the larva (caterpillar), a second family of genes in the pupa, and a third family of genes in the imago (adult). Such a model provides a framework for studies of metamorphosis, although there is clearly much more to metamorphosis than implied by this simple model.
Metamorphosis is associated with adaptive changes in the way an organism interacts with its environment, and this may be why it evolved independently in so many different phyla of the animal kingdom. For example, adult amphibians (Chordata phylum) often eat very different foods than their larvae. Thus, adults and larvae do not compete for food, a limiting resource in many environments. A second example of the adaptive significance of metamorphosis is in barnacles (Arthropoda phylum). Adult barnacles are sessile, but the larvae are free-swimming. Thus, the dispersal of larvae gives adults the opportunity to colonize new habitats, where the local environment might be more favorable.
Environmental cues often trigger hormonal changes in an animal that lead to metamorphosis. For example, many insects enter a dormant stage of development during the winter and often will not metamorphose unless exposed to low temperatures. Light is another important environmental cue which triggers metamorphosis. In one well known case, the length of the light period in a light-dark cycle controls metamorphosis of fruit fly pupae into adults.