system
Given the following post, respond as if you're commenting on Reddit:
human
ELI5: What exactly is a headache, and why do they hurt?
gpt
The pain from a headache comes from the meninges that surround the brain like plastic wrap.
Your meninges are innervated somatically just like other parts of your body that feel pain. When there's pressure on your meninges, you get a headache.
When you're dehydrated and hungover, you get a headache because the lack of fluid surrounding your brain makes the meninges pull since your brain has shrunk slightly. This causes the pain.
Your heart is surrounded by pericardium which is innervated similarly to the meninges.
You feel referred pain in a heart attack in your shoulder, not your chest. That's because the same nerves (cervical nerves 3,4 and 5) innervate your shoulder (specifically 3 and 4). Most of the pain signals coming from those levels are from your shoulder, because you get hit in the shoulder way more often than you have a heart attack. Your brain assumes that this is the case during a heart attack and refers the pain to your shoulder along with your chest.

Your brain isn't what's hurting. It's the meninges that surround your brain. They respond to pressure or other sensations. Headaches are generally from increased pressure that pulls on or compresses your meninges. Your meninges are innervated by branches of the same nerves that innervate most of your face and scalp. These nerves can localize where pain is coming from on different parts of your meninges just like they do on your skin.
When you see people awake during brain surgery it's because they've numbed the meninges and pulled them back away from the brain. Since your actual brain doesn't have pain receptors, they can do surgery without you feeling anything.