An erection happens when blood fills two spongy chambers inside the penis and gets trapped there under pressure. That sounds simple, but it actually requires a precise chain of events involving your brain, nerves, hormones, and blood vessels all working together. Understanding how each piece contributes helps explain why erections sometimes don’t cooperate and what you can do about it.
How the Signal Starts
Erections begin in one of two ways, and often both at once. The first is physical touch. When your genitals are stimulated, sensory nerves in the lower spine (at sacral segments S2 through S4) send a signal through the pelvic nerves that triggers a parasympathetic response, essentially flipping a “relax and fill” switch in the blood vessels of the penis. This is called a reflexogenic erection, and it can happen even without any sexual thoughts. It’s the reason people with certain spinal cord injuries can still get erections from direct contact.
The second pathway is purely mental. Sexual thoughts, fantasies, memories, or visual cues activate a region of the hypothalamus called the medial preoptic area, which acts as a central hub for sexual behavior and reward. This area receives input from parts of the brain involved in emotion and memory, then sends signals down the spinal cord to kick off the same physical process. These psychogenic erections happen without any touch at all.
In most real-world situations, both pathways fire simultaneously. You’re being touched and you’re mentally aroused, and the two signals reinforce each other.
The Chemical Chain Reaction
Once the nerve signal arrives at the penis, the key molecule is nitric oxide. Nerve endings and cells lining the blood vessels release nitric oxide, which passes into the smooth muscle cells surrounding the penile arteries and spongy tissue. There, it triggers production of a signaling molecule called cGMP. Rising cGMP levels cause calcium to drop inside those muscle cells, and when calcium drops, the muscle relaxes.
That relaxation is the critical event. The arteries widen, and the spongy chambers (the corpora cavernosa) open up to accept a rush of incoming blood. In a healthy erectile response, the peak blood flow velocity through the penile arteries exceeds 30 cm per second. Below 25 cm per second, there’s typically not enough arterial flow to produce a full erection.
How Blood Gets Trapped
Filling with blood is only half the equation. Staying hard requires that blood be locked in place. The corpora cavernosa are wrapped in a tough, fibrous sheath. As the spongy tissue expands with blood, it presses the veins against this outer sheath, physically pinching them shut. Blood flows in through the arteries but can’t drain back out through the veins. The result is sustained rigidity under pressure, and it stays that way as long as the chemical signals keep the smooth muscle relaxed and the veins compressed.
When arousal fades or after orgasm, the sympathetic nervous system takes over. Nitric oxide production drops, cGMP breaks down, smooth muscle contracts again, the arteries narrow, and the veins reopen. Blood drains out, and the penis returns to its soft state. The whole system is essentially a hydraulic lock controlled by chemistry.
Where Testosterone Fits In
Testosterone doesn’t directly cause erections the way nitric oxide does, but it sets the stage. It maintains sex drive, supports the health of erectile tissue, and helps regulate nitric oxide production. Research on the dose-response relationship between testosterone and erections has found that erectile function holds up across a wide range of testosterone levels, even down to about 10 to 12 percent of normal concentrations. Below that threshold, erectile function drops off in a dose-dependent way: the lower the level, the worse the function.
This means moderately low testosterone might not noticeably affect your erections, but severely low levels almost certainly will. If testosterone is the issue, the first signs are usually reduced desire rather than a sudden inability to get hard.
What Happens During Sleep
Healthy men typically get erections during REM sleep, averaging about two to three episodes per night with a combined duration of roughly 40 minutes. These nocturnal erections aren’t about sexual dreams. They appear to serve a maintenance function: over two-thirds of the blood supply and metabolic exchange in erectile tissue happens during these sleep erections. Chronic disruption of REM sleep, whether from sleep apnea, frequent nighttime urination, or other causes, can reduce these episodes and may contribute to erectile problems over time.
Nocturnal erections also have diagnostic value. If you’re having trouble getting hard while awake but still waking up with morning erections, that’s a strong sign the plumbing works fine and the issue is more likely psychological or situational.
Lifestyle Factors That Affect Blood Flow
Because erections depend so heavily on blood vessel health and nitric oxide, anything that damages your cardiovascular system hits erectile function too. Erectile dysfunction is often an early warning sign of heart disease, sometimes appearing years before other cardiovascular symptoms. The penile arteries are small, so they clog or stiffen before larger vessels do.
On the flip side, habits that improve blood vessel function directly support erections. Exercise is the most consistently effective lifestyle factor, both because it improves cardiovascular fitness and because it boosts the body’s ability to produce nitric oxide. Even moderate aerobic activity, like brisk walking, makes a measurable difference.
Diet plays a role too, particularly foods rich in dietary nitrate. Your body converts nitrate from food into nitrite (with help from bacteria on the surface of your tongue), and then into nitric oxide. Beetroot, spinach, arugula, and lettuce are among the highest sources, containing over 250 mg of nitrate per 100 grams. After eating these foods, nitrate levels in your blood rise within about 30 minutes and peak around 90 minutes, with the downstream nitric oxide effects peaking at two to three hours.
Smoking, heavy alcohol use, and a sedentary lifestyle all work in the opposite direction. They reduce nitric oxide availability, stiffen arteries, and impair the smooth muscle relaxation that makes the entire process possible. Excess body fat also lowers testosterone and increases inflammation, both of which compound the problem.
Why It Sometimes Doesn’t Work
Because so many systems have to coordinate, there are many points where things can break down. Nerve damage from diabetes or surgery can interrupt the signal. Clogged or stiffened arteries can limit blood flow. Damaged venous tissue can fail to trap blood properly, leading to erections that fade quickly. Low nitric oxide production, whether from aging, smoking, or metabolic disease, weakens the chemical trigger. Anxiety, depression, and stress can suppress the psychogenic pathway, overriding physical signals with sympathetic nervous system activity that actively works against erection.
Medications can interfere too. Blood pressure drugs, antidepressants, and antihistamines are common culprits. And the relationship often goes both ways: the stress of experiencing erectile difficulty makes the next attempt harder, creating a cycle that’s psychological and physical at the same time.