The transformation of a caterpillar to a butterfly is amazing. It’s a type of recycling, like a plastic bottle dropped off in the recycling bin and is melted down into an entirely different shape. That’s basically the idea behind what happens inside the chrysalis, or more commonly called the cocoon.
Most of the body breaks itself down into imaginal cells, which are undifferentiated like stem cells and they can become any type of cell. The imaginal cells put themselves back together into a new shape. A few parts of the body, such as the legs, are more or less unchanged during this process. This process of complete transformation is known as holometabolism.
The amount of time required to transform completely varies from one species of caterpillar to another, but in general it takes about two weeks. For species that survive the winter by staying in the chrysalis, it can take months.