Let's say you sprained your ankle or burned your finger. Nerve fibers immediately send a signal to your brain, which decodes the sensation as pain.
No wonder modern surgery is only possible after the discovery of anesthesia. However, if it is the brain itself that is the object of surgery, it has no need for anesthetics.
Nerve cells of the brain send themselves the same signals as in the case of a broken limb, but there is no data processing center for them. The brain, used to be in charge of the whole organism, has no idea when it should be in pain itself.
Here's the creepy part, but patients are often fully conscious during brain surgery, allowing the surgeons to see if they've gone too deep into our body's main processor.