Scientists say people swear when they hurt themselves because it actually reduces the pain.
A study by researchers at Keele University found volunteers were able to withstand pain for longer when they swore.
Dr Richard Stephens, who led the study, believes it may explain why swearing is common in languages all over the world.
"Swearing is quite an emotional form of language and it is an almost universal human linguistic phenomenon," he said.
"When my wife was in labour with our daughter she felt the need to f and blind at one point, but was very apologetic afterwards. The midwife said they were used to that kind of language on the delivery ward, so it got me thinking.
"Our research shows one potential reason why swearing has developed and why it persists."
The researchers, whose findings are published in the journal NeuroReport, tested 64 students' tolerance to pain by asking them to submerge their hand in a tub of ice water for as long as they could while repeating a series of swear words of their choice.
They were then asked to carry out the task again while repeating non-offensive words they would use to describe a table.
They found that volunteers who swore were able to keep their hands submerged in the water for an average of 40 seconds longer. They also rated their pain lower.
.
.