You stick yourself with a pencil, or maybe get pinched in a closing door.
Your first response is a little cry and a flinch that draws the hurt place away from the source of pain - two behaviors which are easy to understand. But what about the next thing you do - rubbing the area where you got the ouch? Why do that?
You might think the last thing you would want to do with a sore spot is touch it. In fact, the reason rubbing reduces the pain of minor sticks and bruises is that you aren't actually rubbing the hurt area itself; or, if your hand does cross over it, you won't tend to focus on that spot. Rather, you rub the immediate area all around the hurt. This works to diminish the pain by signalling a great many nerve fibers to fire in the same immediate vicinity, thus "drowning out" those nerve fibers which are sending the "ouch" signal.
Think of a stadium full of people: each person represents one of the nerve fibers in your arm. If fifty of them are shouting "ouch!" and a hundred and fifty are silent, the "ouches" have it. Not so, however, if fifty are shouting "ouch" and a hundred and fifty are saying "rub." Although the pain signal itself has not been altered, its overall perceived effect will not be as intense.
Why don't two pinches cancel each other out, then? Rubbing is especially effective at drowning out small pain signals precisely because it is not the same kind of signal - that is, an acute, localized message.