An erection happens when blood fills the spongy tissue inside the penis, making it firm and stand upright. This is a normal body function that begins even before birth and becomes much more noticeable during puberty. Understanding the basic process can help make sense of why erections happen when they do, and why they sometimes seem to happen for no reason at all.
What Happens Inside the Body
The penis contains two columns of spongy tissue that run along its length. In their resting state, the small arteries leading into this tissue are partially closed, and only a small amount of blood flows through. When the body sends a signal to start an erection, nerve endings in the penis release a chemical messenger called nitric oxide. This messenger tells the smooth muscle lining the arteries and spongy tissue to relax and open up.
Once those muscles relax, blood rushes in and fills thousands of tiny spaces within the spongy tissue, like water filling a sponge. As the tissue expands, it presses against a tough outer sheath that wraps around each column. This sheath is normally about 2 to 3 millimeters thick, but it stretches and thins to as little as a quarter of a millimeter during an erection. Because it can only stretch so far, it compresses the veins that would normally drain blood out of the penis. Blood flows in but can’t easily flow out, and the result is a firm erection.
When the triggering signal fades, the muscles tighten back up, the arteries narrow, blood drains through the veins, and the penis returns to its soft state. The whole process is controlled by the nervous system and happens automatically.
The Two Main Triggers
There are two distinct pathways that cause erections, and they work through different parts of the spinal cord.
Mental arousal. Seeing, hearing, or thinking about something sexually exciting sends signals from the brain down through the upper spinal cord. These are called psychogenic erections. They’re the type most people think of first, and they depend on nerve pathways in the middle-to-lower back region of the spine.
Physical touch. Direct contact with the genitals sends nerve signals to the lower spinal cord, which can trigger an erection on its own without any involvement from the brain. These are called reflexogenic erections. This is why erections can happen from physical stimulation even when a person isn’t thinking about anything sexual. The two systems can also work together, with mental arousal and physical touch reinforcing each other.
Why Erections Happen During Sleep
Healthy males experience erections during sleep regardless of what they’re dreaming about. These happen during REM sleep, the phase associated with vivid dreams, and the reason is neurological rather than psychological. During REM sleep, the part of the nervous system that normally suppresses erections (the sympathetic nervous system) essentially switches off in a specific area of the brainstem. With that brake removed, the body’s natural pro-erection signals take over.
Because there are several REM cycles each night, a person can have up to five erections during a single night of sleep, each lasting 20 to 30 minutes. This is why waking up with an erection is so common. It typically just means you woke up during or right after a REM cycle.
Puberty and Spontaneous Erections
During puberty, rising testosterone levels drive major changes in the reproductive system. Testosterone plays a direct role in penile development and affects the tissues that make erections possible. As these hormone levels climb, the body becomes far more responsive to both physical and mental triggers.
The result is that boys going through puberty frequently get erections that seem to come out of nowhere. These spontaneous erections can happen without any physical touch and without any sexual thoughts. They might show up during class, on the bus, or at other inconvenient moments. This is one of the most common concerns boys have about puberty, but it happens to everyone going through this stage of development. Over time, as the body adjusts to its new hormone levels, these random erections become less frequent.
Erections Before Puberty
Erections aren’t something that starts at puberty. They occur throughout childhood and have even been observed in ultrasounds before birth. In infants and young boys, erections are a simple reflexogenic response, often triggered by a full bladder, a diaper change, or other physical contact. They have no sexual component at that age. They’re simply evidence that the basic nerve-and-blood-flow mechanism is functioning normally.
The Nervous System’s Role
Erections reflect a constant tug-of-war between two branches of the autonomic nervous system, the part of the nervous system that runs on autopilot. The parasympathetic branch promotes erections, while the sympathetic branch (the same one responsible for your “fight or flight” response) works against them. This is why stress, anxiety, or nervousness can make it difficult to get or maintain an erection. When the sympathetic system is highly active, it overrides the signals that would otherwise allow blood to flow in.
The brain also releases oxytocin during arousal, which activates nerve pathways from the spinal cord to the penis and strengthens the erection response. Meanwhile, serotonin, another brain chemical, tends to have the opposite effect, which is one reason certain medications that increase serotonin levels can affect erections as a side effect.
Why Erections Sometimes Don’t Cooperate
Because erections depend on blood flow, nerve signals, hormones, and mental state all working together, there are many reasons they can behave unpredictably. Getting an erection at an unwanted time is normal, especially during puberty. Not getting one when you want one is also normal and can happen from stress, fatigue, alcohol, or simply being distracted. Neither situation means something is wrong.
Since the process is essentially a vascular event (blood flowing in, being trapped, then flowing out), anything that affects cardiovascular health can also affect erections over the long term. Regular physical activity, adequate sleep, and general health all support the system working as it should.