To learn why, just
The connection between expletives and pain relief is not really clear, but a deep and primal part of the brain is activated when swearing, which is not usually activated when speaking. This area of the brain is related to the flight-or-fight response to stress and when activated it increases the heart rate, which makes us less sensitive to pain.
Richard Keele the psychologist that led the study said, "Swearing is such a common response to pain that there has to be an underlying reason why we do it. I would advise people, if they hurt themselves, to swear." Like most things in life, moderation is key for a string of expletives to work as pain management. The more you swear the less potent the pain relief. Do weigh in on your relationship with swearing over on TrèsSugar.