Butterfly caterpillars molt four or five times as they grow. Each different caterpillar stage is called an instar.
In the photo below you can see the caterpillar’s crumpled discarded exoskeleton.
The caterpillar first grows a new skin under its old skin. Then the caterpillar draws its head out of its head capsule. Occasionally it will need to use its front legs to help remove the head capsule. Next the caterpillar crawls out of its old skin. This is called molting. After the molt and while the new skin is soft and pliable the caterpillar swallows a lot of air, which expands the body. As the new exoskeleton hardens it lets out the air to allow room to grow.
Molting takes a great deal of energy and after each molt, the caterpillar rests quietly for a brief period before then eating its discarded exoskeleton.