Central pain modulation
Before the pain signal reaches the sensory cortex it passes by a system of neurons where the intensity of the pain signal can be modulated. This system involves efferent (descending) neurons in the midbrain (periaquaductal grey matter), which receive input from neurons from the frontal cortex and hypothalamus. The neurons in the midbrain control/inhibit the pain transmission neurons in the dorsal horn via neurons in the medulla (Raphe nucleus).
The axons of the Raphe nucleus descend and stimulate the interneurons in the dorsal horn and can thus (indirectly) inhibit the transmission neuron.
The analgesic effect from the descending pathways can be established by the neurotransmitter enkephalin (endogenous opioid). Enkephalin binds to the opioid receptor on the synapse of a pain transmitting neuron. This binding results in inhibition of neurotransmitter release and thus in reduced pain transmission.
Enkephalin and β-endorphin are both endogenous opioids.
Serotonin is an excitatory neurotransmitter.