If you’re having heterosexual sex, the straight (heh) answer is this: The average time it takes men to ejaculate after entering the vagina is seven minutes, so add another 30 minutes of foreplay in front of that to get a total of about 40 minutes, says board-certified urologist and men’s sexual health expert Paul Turek, M.D. Some studies say that the average is more like five and a half minutes, though—and it does make sense that there’s some variance, given the self-reported nature of the matter.

However, there’s more to all of it than just the numbers—so if you’re curious about how to last longer (and why you may have trouble staying hard in the first place), read on…

It seems like guys have always wanted to talk about their penises—to the extent that we wouldn’t be surprised if, some 10,000 years ago, there were cavemen who bragged about how long they could keep it up (not to mention dudes who exaggerated their size).

And as long as this kind of bragging has been going on, there have also been men who think about their own performance and wonder if it’s normal—or wonder what “normal” even means. It’s easy to think there’s something wrong when there actually isn’t (at least in part due to some pretty tall tales).

What keeps you from keeping it up?

“It really depends on a lot of things: sexual arousal, mood, stress, health, situation, fatigue, sleep, traffic—just about everything else that impacts our daily lives,” Turek says.

According to Brianna Rader, a relationship and sex educator and founder of the Juicebox sex and relationships app, there are a variety of worries can lead to erection issues too:

  • Fear that you won’t perform well in bed and satisfy your partner
  • Poor body image, including concern over your weight
  • Problems in your relationship
  • Worry that your body won’t “measure up”
  • Concern about ejaculating too early or taking too long
  • Anxiety about not being able to finish or enjoy the experience

“Erection issues are often viewed as a dysfunction, when, in reality, they tend to be a normal response to environmental or emotional stress,” Rader says.

Frustratingly, if you’ve been having trouble keeping it up, your penis is probably getting and staying hard when you can use it the least. “At night, while in deep sleep (unbeknownst to them), men frequently have at least three erections lasting one hour each,” Turek says.

So what can you do about it?

Duration-enhancing creams, or “male desensitizers,” like this one from K-Y, are sometimes an option, and according to Turek, they are very safe but are really only useful in cases of lifelong early ejaculation. “When used outside of this indication, they can be so effective that in many cases they can make it virtually impossible to get and keep an erection,” Turek says.

Men often get their initial experience with erections and orgasms when masturbating, and this can help them when they’re with a partner—however, their methods can also impact issues they have with a partner. “The good news is that you can retrain yourself to become erect in different environments with your partner or with different sensations, but it may take some time and effort,” Rader says.

This is because many men have honed a specific technique for their masturbation sessions, Rader says. “For men who take a long time to orgasm or struggle to orgasm with partners, it may be because, for years, they’ve masturbated with a very tight grip and can’t orgasm without that type of pressure.

“For men who can’t get hard with a partner, it’s possible—if there’s no underlying medical issue, like a blood pressure condition that requires a consultation with a physician—that they’ve masturbated with a specific technique for years and have trouble responding to a partner’s different style of touch. Or they’ve masturbated in a way that they can’t replicate with a partner (for instance, many men have masturbated with pillows),” Rader says.

“Others may have been focused on climaxing and getting masturbation over quickly, perhaps to avoid getting caught or from being taught that masturbating is wrong,” Rader says. “So they’ve become accustomed to going straight for the climax and have trained themselves to orgasm in less than two minutes.”

For some people, premature ejaculation doesn’t derive from this kind of training and occurs in two varieties: (1) lifelong premature ejaculation and (2) acquired premature ejaculation.

Men in their 20-40s who suffer from premature ejaculation are often dealing with “lifelong” premature ejaculation. This appears to be a genetically determined problem, sometimes with an inheritance pattern, and there’s medical therapy that can be effective. Acquired premature ejaculation is less common and sometimes related to other problems.

A potential solution for these three scenarios is practice and a shift in mindset. “If you have premature ejaculation, you can start trying to double the length of your masturbation sessions. If you want to last 10 minutes with a partner, then don’t let yourself orgasm in less than 10 minutes while masturbating. You’ll likely need to build up to this point. Start with changing two minutes to four minutes.”

Kegel exercises may also help with this, Rader says—and yes, there are Kegels for men too. And if you’ve just been going at it with too much of a chokehold, go slower, softer, and try different sensations, she says—during these sessions, you’ll become more aware of what’s triggering your orgasm.

Medication may be helpful for some too.

“While taking the erectogenic agents like Viagra or Cialis, the erection might be a better one, but they only give you a longer erection if you ‘will’ them to,” Turek says. “When you stop willing the erection to happen, the erection falls—just like without medication.”

SSRIs (antidepressant medications) have also been shown to be incredibly effective in helping men with premature ejaculation.

But be aware, there can be too much of a good thing. You and your partner don’t actually need or want that erection to last ALL night. “I don’t advise men to maintain erections for more than three hours at any one time—this is called priapism, and it puts the penis at risk of not getting enough oxygen, which can result in scar tissue and poor erections in the future. We send those men to the emergency room!” Turek says.

Aly Walansky is a New York-based lifestyle writer. Follow her on Instagram and Twitter @alywalansky.