Cocoon, a tough bag or case spun by the larva of certain insects for protection during the pupa, or resting, stage. The cocoons most commonly seen are those spun by the caterpillars of moths. A modified salivary gland opening through the caterpillar's mouth secretes the silk that is used to spin the cocoon.

Among the most perfect cocoons is that of the silkworm. It is formed entirely of silk. Other caterpillars spin cocoons of silk mixed with their own hair, or use the silk merely to bind together bits of leaves, twigs, soil, or other materials. Some cocoons contain as much as 2,500 feet (760 m) of continuous thread. Cocoons are usually fastened to twigs, or are spun inside folded leaves.

The spinning may last several days. The caterpillar swings its head in a circle while casting out a fine, sticky thread that dries into tough silk when it is exposed to air. The outside of the cocoon is spun first, then the lining. When the lining is completed, the caterpillar sheds its skin for the last time and becomes a smooth, almost motionless pupa.

The pupaThe pupa of a moth enclosed in the silken cocoon.

Adult moths emerge from the cocoons in various ways. Some bite through the tough cocoon wall with their jaws. Others may use their temporary spines or plates to cut through the threads. The adult silk moth secretes a solvent that softens the walls of the cocoon.

One general distinction between moths and butterflies is that moths spin cocoons, but butterflies do not.

The term cocoon is also used for the egg cases spun by spiders and secreted by earthworms.