An erection is a hydraulic event: your brain or body sends a signal, blood rushes into the spongy tissue inside the penis, and a tough outer membrane traps that blood under pressure to create rigidity. The whole process depends on your nervous system, blood vessels, and a specific chain of chemical signals working together. Here’s how it actually works, step by step.
What Happens Inside the Penis
The penis contains two chambers of spongy tissue that run along its length. When you’re not aroused, the smooth muscle surrounding these chambers stays contracted, limiting blood flow to a trickle. The penis stays soft because there’s simply not much blood in it.
When arousal kicks in, your brain sends signals through your nerves that tell that smooth muscle to relax. The key messenger is nitric oxide, a gas released by nerve endings and blood vessel walls inside the penis. Nitric oxide triggers the production of a second chemical messenger called cGMP, which does the heavy lifting: it forces the smooth muscle cells in the blood vessel walls to unclench. Once those muscles relax, the arteries widen and blood floods into the spongy chambers.
As the chambers fill and expand, they press against a thick, fibrous outer shell that surrounds them. This shell compresses the small veins that would normally drain blood back out of the penis, essentially pinching off the exit routes. Blood flows in faster than it can leave, pressure builds, and the penis becomes rigid. That’s the erection. It stays firm as long as that pressure balance holds.
Your Brain and Nervous System Run the Show
Erections aren’t just one thing. They can be triggered in completely different ways depending on the situation, and different parts of your nervous system handle each one.
The first type is what you’d expect: you see, hear, smell, or think about something sexually arousing, and your brain sends signals down the spinal cord to the blood vessels in your penis. A region in the hypothalamus (a deep, central part of the brain) plays a critical role in processing sexual cues and firing up the pathways that lead to erection. The brain chemicals dopamine and oxytocin both activate these pathways, while serotonin tends to put the brakes on.
The second type is reflexive. Physical touch to the penis or surrounding area sends sensory signals through a nerve in the pelvis to a cluster of neurons in the lower spinal cord, sometimes called the “erection center.” These spinal neurons can trigger an erection on their own, without any input from the brain. That’s why erections can happen from friction or pressure even when you’re not mentally aroused.
The third type happens while you sleep.
Why You Get Hard in Your Sleep
During REM sleep, the phase when most dreaming occurs, your nervous system shifts gears. The “fight or flight” side quiets down and the “rest and digest” side takes over. This shift suppresses the signals that normally keep the penile blood vessels constricted, essentially removing the brakes on erection. The result: your penis gets hard automatically, without any sexual dream or stimulus required.
Men typically have three to five erections per night during REM cycles, each lasting up to 20 or 30 minutes. Morning erections happen because you often wake up at the tail end of a REM cycle. Testosterone levels also peak in the early morning, which increases the frequency of these nighttime erections. A full bladder may contribute too, since the pressure stimulates spinal nerves that can reflexively trigger an erection.
Nocturnal erections are actually a useful health signal. Their presence suggests that the blood vessels and nerves in the penis are working properly, which helps distinguish physical causes of erectile problems from psychological ones.
How an Erection Goes Away
Erections operate on a balance between two competing branches of the nervous system. The parasympathetic branch promotes erection; the sympathetic branch opposes it. When arousal fades, or after orgasm, the sympathetic system reasserts itself. It releases chemicals that cause the smooth muscle in the penis to contract again, squeezing down on the blood-filled chambers. The outer shell stops compressing the veins, blood drains out through the reopened exit routes, and the penis returns to its soft state.
This balance is also why stress, anxiety, or a sudden adrenaline rush can kill an erection. Sympathetic activation, the same system that fires during a stressful moment, directly counteracts the relaxation signals that keep blood trapped in the penis.
Random Erections Are Normal
If you’ve ever gotten hard at an inconvenient or seemingly random time, that’s just your nervous system doing its thing. Slight pressure from clothing, a shift in posture, a fleeting thought, or a minor hormonal fluctuation can be enough to tip the balance toward the parasympathetic side and trigger blood flow. This is especially common during puberty and young adulthood when testosterone levels are high, but it can happen at any age. These erections aren’t a sign of anything wrong. They’re evidence that your vascular and neurological systems are functioning.
What Keeps the System Working Well
Because erections depend entirely on healthy blood flow and nerve signaling, anything that damages blood vessels or nerves can interfere. The major factors that protect erectile function are the same ones that protect your heart: regular exercise, not smoking, moderate or no alcohol intake, maintaining a healthy weight, and managing conditions like diabetes and high blood pressure. All of these directly affect how well your arteries can dilate and deliver blood when needed.
Mental health matters just as much. Anxiety, depression, chronic stress, and sleep deprivation all shift your nervous system toward sympathetic dominance, which works against the relaxation response erections require. The system is sensitive to both physical and psychological inputs, which is why erectile difficulties often involve a mix of both.
When an Erection Lasts Too Long
An erection that won’t go away on its own and lasts longer than four hours is a medical emergency called priapism. When blood stays trapped in the penis for that long without circulating, it becomes starved of oxygen, which can permanently damage the tissue. This is rare, but if it happens, it requires urgent treatment at an emergency room. It’s most commonly associated with certain medications, blood disorders like sickle cell disease, or spinal cord injuries.

