When the piloerector muscle, also known as the (arrector pili muscle) contracts, it causes the hair to stand erect, resulting in goosebumps.

This contraction is often triggered by cold temperatures or emotional stress, according to a systematic review on ScienceDirect.com.

The erect hairs trap a layer of air, which helps to insulate the body and retain heat.

Here's a more detailed explanation below.

Mechanism:

Nerve impulses from the brain signal the piloerector muscles to contract, according to the BBC.

Function:

The primary function of this muscle is to raise the hairs when the body is cold or when the individual is experiencing strong emotions..

Goosebumps:

The raised hair causes the skin to form small bumps, which are commonly known as goosebumps.

Insulation:

The erect hairs trap a layer of air close to the skin, providing insulation and helping to prevent heat loss.

Other Roles:I

n some animals, piloerection is used for camouflage or to make the animal appear larger to deter predators.

More Info: www.elsevier.com