Algolagnia (from the Greek 'algos' meaning pain and 'lagnia' meaning lust) is a paraphilia of deriving sexual pleasure from physical pain.
It may have a simply biological basis, as it is proven that pain, just like sensorial pleasures such as sexual contact and sweet foods, causes the release of endorphins, the chemicals that induce pleasure.
If a person's pain threshold is sufficiently high, this may outweigh the normal discomfort, even to the point of addiction.
Note that algolagnia is not the same thing as physical masochism, since there are fewer psychological connotations to algolagnia, which may be a simple liking for pain, without any need for domination, submission or humiliation. It may therefore rather take the form of self-infliction of pain.