As the caterpillar grows, its exoskeleton (i.e. its outer cuticle/skin) becomes tight, so it sheds it. This process is called molting.
Ecdysone is the molting hormone of insects and it is this that causes an insect to molt.
The caterpillar releases an enzyme that dissolves the inner layer of its cuticle (skin). Then it expands its body and splits the cuticle to enable it crawl out of it. The critical part is dissolving the inner layer to separate themselves from it. Their cuticle isn't living like our skin (which is why, although we call it a skin, it isn't really 'skin') and is more like a fingernail. The head capsule is the first part of the old skin to come off during the molting process. Then the old skin peels back from the front of the caterpillar.
Caterpillars will do this four or five times as they grow. Each different growth stage is called an instar.
Edith Smith - http://www.butterflyfunfacts.com/