In the spinal cord, signals from touch and movement sensors switch on small brake cells. Those brake cells quiet pain signals before they travel up to the brain. That is textbook.
The 1965 drawing of this has been changed over time, but the main idea held.
For adjustments, there is more. In rats, a joint move eased soreness through calming chemicals the brain sends down the cord. In people, pressure had to be pressed harder before it hurt, even far from the spot adjusted.
Which part would you like explained more?