There are no pain receptors in the brain itself. But he meninges (coverings around the brain), periosteum (coverings on the bones), and the scalp all have pain receptors. Surgery can be done on the brain and technically the brain does not feel that pain.
With that said, the brain is the tool we use to detect pain. Let’s say you’re on the beach and you step on a sharp shell. Special pain receptors in your skin activate whenever there has been an injury, or even a potential injury, such as breaking the skin or causing a large indentation. Now, an impulse is heading through the nerve into the spinal cord, and eventually all the way to your brain. This happens within fractions of a second.
Your spinal cord is a complex array of nerves, transmitting all kinds of signals to and from the brain at any given time. The spinal cord is also in charge of your reflexes. The brain does not have to tell your foot to move away from the shell, because the spinal cord has already sent that message. The pain signal continues to the brain. This is because pain involves more than a simple stimulus and response. Your brain needs to make sense of what has happened. Pain gets catalogued in your brain’s library, and emotions become associated with stepping on that shell. When the pain signal reaches the brain it goes to the thalamus, which directs it to a few different areas for interpretations. Some areas in the cortex figure out where the pain came from and compare it to other kinds of pain with which is it familiar. Was it sharp? Did it hurt more than stepping on a tack? Have you ever stepped on a shell before, and if so was more or less painful?
Signals are also sent from the thalamus to the limbic system, which is the emotional center of the brain. Feelings are associated with every sensation you encounter, and each feeling generates a response. For example, your heart rate may increase, and you may break out into a sweat.