Goosebumps are caused by the stress hormone adrenaline, which is released when we're cold or afraid. Adrenaline prompts the tiny muscles attached to our body hair to contract. As a result, our hair stands upright and our flesh appears bumpy.
Goosebumps are actually a defense mechanism that dates back to when humans still had a full coat of hair on their bodies. Prompting the hair to stand on end would help our ancestors stay warm, and also make them look more intimidating when they were threatened by a predator.