How Pain Works

Let’s say that you stub your toe. Nerves in the toe known as nociceptors, tasked with sensing pain, go into action. They send messages to the spinal cord that pain has occurred; the worse the stub, the more rapidly and powerfully they fire. The spinal cord then releases neurotransmitters to the brain’s thalamus, communicating with the brain that there’s an injury. But there’s not just one part of the brain that processes pain. The thalamus could forward the message on to the part of the brain that manages physical sensation as well as the part that controls emotions, memory, and attention.

https://science.howstuffworks.com/life/inside-the-mind/human-brain/pain.html