The penis gets hard because blood rapidly fills two sponge-like chambers inside it and then gets trapped there under pressure. This process is triggered by signals from your brain or direct physical touch, both of which set off a chain of chemical reactions that relax the blood vessel walls and allow a surge of blood flow. The entire mechanism depends on a precise coordination of nerves, blood vessels, hormones, and specialized tissue.
What Happens Inside the Penis
The penis contains two cylindrical chambers called the corpora cavernosa, which run along its length. These chambers are made of spongy tissue filled with tiny blood spaces, similar to a dense network of small pockets. In a soft (flaccid) state, the smooth muscle lining these spaces stays contracted, limiting blood flow in and allowing blood to drain out freely.
When you become aroused, nerve endings in the penis release a gas called nitric oxide. This small molecule triggers a chain reaction: it activates an enzyme that produces a signaling molecule (cyclic GMP), which tells the smooth muscle cells in the blood vessel walls and spongy tissue to relax. Once those muscles relax, the small arteries feeding the penis open wide and blood rushes into the spongy chambers, expanding them rapidly.
Here’s the critical part that actually creates rigidity. The corpora cavernosa are wrapped in a tough, fibrous sheath called the tunica albuginea. As the spongy tissue swells with blood, it presses outward against this sheath. The expanding tissue compresses the small veins that would normally drain blood out of the penis, essentially trapping the blood inside. This is called the veno-occlusive mechanism, and it’s what maintains the high internal pressure that makes the penis rigid. Research on cadaveric tissue has confirmed that the outer layer of this sheath plays an essential role in sealing off venous drainage.
Two Different Triggers
Not all erections start the same way. Your body has two distinct pathways that can initiate one.
Psychogenic erections start in the brain. Visual stimulation, sounds, fantasies, or emotional arousal send signals down the spinal cord from the upper lumbar region (around the T11 to L2 vertebrae) to the penis. This is why you can get an erection from a thought alone, without any physical contact.
Reflexogenic erections bypass the brain entirely. Direct physical stimulation of the genitals sends nerve signals to the lower spinal cord (around the S2 to S4 vertebrae), which triggers the same blood-flow response through a local reflex arc. This is why erections can occur even during sleep or in people with certain spinal cord injuries that disconnect the brain from the lower body.
In most real-world situations, both pathways work together. Mental arousal primes the system while physical touch amplifies the response.
Why Erections Happen During Sleep
Healthy adults typically experience four or five erections per night, timed to periods of REM sleep. Each erection cycle lasts roughly 85 minutes on average, with the penis being fully or partially erect for about 25 minutes of that cycle. These are called sleep-related erections, and they happen automatically regardless of dream content.
During puberty, sleep-related erections make up over 30% of total sleep time in boys aged 13 to 15. That proportion gradually decreases with age, dropping to around 20% of sleep time for men in their 60s. The exact purpose of these erections isn’t fully settled, but they appear to help maintain the health of erectile tissue by regularly oxygenating it with fresh blood flow. Their presence is also a useful clinical sign: if someone has erections during sleep but not while awake, the issue is more likely psychological than physical.
The Role of Testosterone
Testosterone doesn’t directly cause erections, but it keeps the underlying machinery working. One of its key jobs is maintaining the production of nitric oxide, the molecule that kicks off the entire blood-flow cascade. Animal research has shown that testosterone increases the activity of the enzyme responsible for producing nitric oxide in a brain region involved in sexual behavior. When testosterone drops significantly, as it does after castration in animal models, the number of neurons producing this enzyme decreases measurably.
Testosterone also influences sexual desire and arousal at the brain level, which affects how readily psychogenic erections occur. Men with very low testosterone often notice reduced spontaneous erections and lower libido before they notice any change in their ability to respond to direct physical stimulation.
How Erections End
The body has a built-in off switch. An enzyme called PDE5 continuously breaks down cyclic GMP, the signaling molecule that keeps the smooth muscle relaxed and blood trapped in the penis. During arousal, nitric oxide production outpaces this breakdown, so the erection holds. Once arousal fades, or after orgasm, nitric oxide release drops off, PDE5 gains the upper hand, cyclic GMP levels fall, and the smooth muscle contracts again. The veins reopen, blood drains out, and the penis returns to its soft state.
This is exactly the mechanism that erectile dysfunction medications target. They block PDE5 from breaking down cyclic GMP, which keeps blood in the penis longer. They don’t create arousal on their own; they simply make the body’s natural erection process more effective once it’s already been triggered.
How Erections Change With Age
The basic mechanism stays the same throughout life, but several components become less efficient over time. Aging men generally need more time and more direct physical stimulation to achieve a full erection. The delay affects every phase of the sexual response: arousal takes longer, peak rigidity may be lower, and the recovery period between erections stretches out considerably.
These changes happen for several overlapping reasons. Blood vessel walls stiffen naturally with age, reducing their ability to dilate quickly. Nitric oxide production tends to decline. Testosterone levels drop gradually, typically about 1% per year after age 30. The elastic fibers in the tunica albuginea can lose some of their flexibility, making the veno-occlusive trapping mechanism less airtight. None of this means erections stop, but the process becomes less automatic and more dependent on direct stimulation and adequate arousal.
What Affects Erection Quality
Because erections depend so heavily on healthy blood flow, anything that damages blood vessels can impair them. Diabetes, high blood pressure, high cholesterol, smoking, and obesity all affect the lining of blood vessels and reduce nitric oxide availability. In fact, erectile difficulty is sometimes the earliest noticeable sign of cardiovascular problems, appearing years before other symptoms, because the small arteries in the penis are narrower than those feeding the heart and are affected sooner.
Psychological factors matter just as much. Stress, anxiety, depression, and relationship tension can suppress the brain signals that initiate psychogenic erections. Performance anxiety creates a particularly frustrating cycle: worry about losing an erection activates the sympathetic nervous system (the fight-or-flight response), which constricts blood vessels and directly opposes the relaxation needed for blood to flow in. Alcohol and certain medications, particularly antidepressants, blood pressure drugs, and antihistamines, can also interfere with the signaling pathway at various points.
On the positive side, regular cardiovascular exercise, adequate sleep, maintaining a healthy weight, and managing stress all support the vascular and neurological health that erections depend on. The system is remarkably responsive to lifestyle changes, particularly in younger men whose blood vessels haven’t yet sustained long-term damage.

