If you’ve always harbored a desire to be cuffed and whipped, you might be a masochist. A masochist is someone who finds painful sexual activities like spanking, biting and whipping to be pleasurable. Sexual masochists want to experience pain when they have sex, and while most masochists are content with milder forms of pain, some can only get off during extreme activities like cutting and electric shock.

To a lot of people, masochism is unsettling. Whereas most of us spend our lives trying to avoid pain, especially during sex, masochists practically beg others to hurt them, sometimes in ways that sound dangerous. Why is that? Where do masochistic desires come from in the first place?

Historically, the prevailing view of the mental health community was that masochists were insane. In fact, until recently, masochism was considered a diagnosable psychiatric condition. (Today, it’s only considered a disorder to the extent that one’s masochistic desires can cause personal distress or impairment in one’s life). This school of thought has largely fallen out of favor thanks to a growing body of research that demonstrates how masochists appear to be as psychologically healthy as everyone else. Scientists no longer believe that masochism stems from general psychological problems, but there are still a few major theories that attempt to explain the psychological desire for pain mixed with pleasure.

Many psychologists have argued that paraphilias—that is, unusual sexual interests—are learned behaviors. Learning theory can therefore help explain not only why some of us become masochists, but also why others have foot and shoe fetishes, become furries and so forth.

So how might masochism be learned? Sometimes, it begins with an observation. For example, if you repeatedly see people enjoying being spanked (as in every other scene in Fifty Shades of Grey), you may be more inclined to try it yourself. Let’s say you asked to be spanked on a day when you’re feeling particularly horny. That will make the ensuing sex all the more hot and your orgasm that much more powerful. These conditions make spanking a rewarding sexual behavior—and rewarded behaviors tend to be repeated.

A lot of us have a hard time enjoying ourselves during sex because of anxieties about our bodies or performance abilities. Those anxieties interfere with sexual enjoyment, which is why social psychologist Roy Baumeister has proposed that masochism is a solution for overly anxious people. The experience of pain, he says, provides a potent distraction from whatever else might be on our minds. In other words, people looking for a psychological escape might be drawn to masochism because it’s a powerful physical distraction that lets you lose yourself in the moment.

A related theory suggests that masochism isn’t just a form of psychological distraction and escape, but rather that it creates an altered state of consciousness, along the lines of what might happen during meditation.

A paper published earlier this year in the journal PLOS ONE found support for this among people who engaged in extreme masochistic rituals that involved receiving temporary piercings with weights attached to them. Researchers found that these people entered a psychological state known as transient hypofrontality, which they described as involving “reductions in pain, living in the here and now, little active decision making, little active logic, and feelings of floating and peacefulness.” What this suggests is that for some people, masochism may be less about the sex and more about achieving a spiritual state.

Masochism may be a way for some people to find personal meaning or value. This theory, also attributable to Baumeister and described in his book Masochism and the Self, begins with the idea that masochism typically occurs in the context of close, ongoing relationships. Masochism isn’t something people usually do with strangers—and for good reason: In a relationship, there’s likely mutual concern and respect for boundaries, which is essential for practicing masochistic activities safely.

When they’re in a safe relationship, it’s not uncommon for masochists to become utterly devoted to their partners. Consistent with this idea, Baumeister found that many masochists says things like “I live to serve” or “My only goal is to please my mistress.” Statements like this suggest that, for some, masochism can become self-defining and may even be seen as a reason to live.

That said, let me be perfectly clear: These theories are not mutually exclusive. I would argue that all of them are likely correct to some degree. And if there’s one thing I’ve learned as a sex scientist, it’s that understanding sexual behavior is incredibly complicated. Although two people might have the same sexual desires, it doesn’t mean the underlying causes of those desires are the same.

Justin Lehmiller, PhD is a sex educator and researcher at Ball State University and author of the blog Sex and Psychology. Follow him on Twitter @JustinLehmiller.