Lets get into the anatomy of pain a little. Nociceptive neurons travel in the peripheral nervous system and are only lightly myelenated. The cell bodies of these nerves reside in the dorsal root ganglion within the spinal cord just before the nerve root extends out. Normal sensory neurons such as those for light touch or pressure are heavily myelenated and conduct quickly but nociceptive neurons conduct more slowly due to the relative lack of myelenation. There are 3 divisions of nociceptive neurons. The first is mechanosensitive meaning it responds to pressure and touch. The second is mechanothermal meaning it responds to heat in addition to pressure and touch and the third is known as a polymodal nociceptor. This is the slowest conducting nociceptor and responds to a variety of stimuli. Also, this stimulus can only reach as far as the thalamus in the brain because it does not register specific pain, but rather dull diffuse pain. In other words, if this nociceptor is activated you would not be able to point and tell someone where exactly the pain is but rather you'd use your whole hand and say “it just hurts all around here”. The somatosensory system in the cortex is activated with sharp pain and is relayed through heavily myelenated delta A fibers rather than the slow, unmyelenated C-fibers of nociception.
When you experience pain that is dull and diffuse such as low back pain, the polymodal nociceptors are active. The pain is also a result of the release of pain stimulating chemical irritants such as prostaglandins, histamins and bradykinin. This are immune cells that invade an area in response to inflammation. Also Substance P is another chemical irritant that is released during inflammatory processes and adds to the feeling of pain. All of these substances cause action potentials in the nociceptor neurons and create the sensation of pain. Analgeics work through influencing these chemicals to eliminate the depolarization of the specific noceceptive neurons that are causing the perception of pain. Once these chemicals cause an action potential in the nociceptive neuron, the nerve depolarizes up through the spinal cord and into the dorsal root (cell bodies). It is there that they synapse on neurons within the dorsal horn within the gray matter of the cord at one or two segments above or below their actual segment of entry. Because of this non-specific course of entry, it, again, creates the perception of diffuse, non specific pain in the area of injury. The nerve continues upward toward the medulla and thalamus via the spinothalamic tract in the antherior lateral horn in the cords white matter.
Part of the modulation of pain occurs through inhibitory descending pathways from the thalamus and hypothalamus. Thalamic neurons descend to the midbrain and there they synapse on ascending pathways in the medualla and spinal cord and actually inhibit incoming nerve signals. This descending inhibition results in production of endorphins, GABA, edynorphins, enkephalins and anandamides.
Exercise promotes the release of all of these, especially GABA and anandamides. People always say that endorphins are released when you exercise but it's still up for debate as to what impact they actually have on the body during exercise. They are not actually able to cross the blood brain barrier and thus shouldn't have a direct affect on the brain. Anandamides however, do cross the blood-brain barrier and current research has shown that they may be whats really responsible for the opiate-like affects of exercise.
The processing of pain, however, is infinitely more complicated than what I described and has many different factors in determining the degree to which we perceive it aside from the severity of the injury. Age, gender, fatigue, and past experiences (memory and limbic system) all influence pain perception.