How Do You Get a Boner? The Science Explained

An erection happens when blood fills two sponge-like chambers inside the penis and gets trapped there under pressure. The process involves your brain, nerves, blood vessels, and hormones all working together in a chain reaction that can start from a thought, a touch, or even happen automatically during sleep. Understanding how it works also helps explain why erections sometimes don’t cooperate.

What Happens Inside the Penis

The penis contains two cylinders of spongy tissue that run along its length. When you’re not aroused, the smooth muscle lining the blood vessels in these chambers stays contracted, limiting blood flow. An erection begins when that muscle relaxes and the small arteries feeding the penis open wide.

The key chemical behind this is nitric oxide, a signaling molecule released by nerve endings and the lining of blood vessels. Nitric oxide triggers a chain reaction that ultimately relaxes the smooth muscle cells in the penile arteries, allowing a rush of blood into the spongy tissue. As the chambers fill and expand, they press against a tough outer sheath (a fibrous casing that wraps around each chamber). This compression squeezes the small veins that normally drain blood out of the penis, trapping the blood inside. Internal pressure rises to roughly 100 mmHg, enough to lift the penis from a hanging position to fully erect. Muscles at the base of the penis then contract to add extra rigidity.

When arousal fades, the chemical signals reverse. The smooth muscle contracts again, blood flow slows, the veins reopen, and the trapped blood drains out.

Three Ways an Erection Can Start

Not all erections begin the same way. There are three distinct types, each triggered through a different pathway.

Mental (psychogenic) erections start in the brain. Seeing something arousing, hearing a voice, remembering a sexual experience, or having a fantasy sends signals down the spinal cord to the nerves that control blood flow to the penis. Visual stimuli are a particularly strong trigger, but imagination alone is enough.

Reflexive erections are triggered by physical touch to the genitals or surrounding area. Sensory nerves in the skin send signals to the lower spinal cord, which activates the erection response directly, sometimes without any conscious arousal. This reflex pathway is why erections can occur during a medical exam or from friction against clothing.

Sleep erections happen automatically during REM sleep. A healthy male can have as many as five erections per night, each lasting 20 to 30 minutes. These aren’t caused by sexual dreams. They appear to be a normal part of the sleep cycle, and their presence is one way doctors distinguish between physical and psychological causes of erectile problems.

The Role of Your Nervous System

Your autonomic nervous system, the part that controls unconscious functions like heart rate and digestion, plays a central role. The parasympathetic branch (your “rest and digest” system) is pro-erection. It triggers the release of nitric oxide and drives blood into the penis. The sympathetic branch (your “fight or flight” system) works against erections. It keeps blood vessels constricted and is responsible for ejaculation and the loss of erection afterward.

This is why stress and anxiety can kill an erection so effectively. When your brain perceives a threat, whether it’s actual danger or just nervousness about sexual performance, the sympathetic nervous system activates. Your body prioritizes functions needed to fight or flee and suppresses ones it doesn’t need in that moment, including erections. The effect is involuntary. You can’t simply will yourself past it, because the same nervous system that would produce the erection is being overridden by the stress response.

Hormones and Blood Vessel Health

Testosterone doesn’t directly cause erections, but it sets the stage. It maintains sex drive, supports the nerve signaling pathways involved in arousal, and helps keep penile tissue healthy. Normal testosterone levels for adult males range from 300 to 800 nanograms per deciliter of blood. Below 300 ng/dL is considered low, and symptoms can include reduced sex drive, low energy, and difficulty getting or keeping an erection. Every person’s baseline is different, though, so some men feel symptoms even within the “normal” range.

The health of your blood vessels matters just as much. The lining of your blood vessels (the endothelium) is responsible for producing nitric oxide. When that lining is damaged by smoking, high blood pressure, high cholesterol, or diabetes, it produces less nitric oxide, and both blood flow to the penis and blood flow to the heart suffer. This is why erectile difficulty and heart disease share the same root cause: damaged blood vessel lining. In many men, erection problems show up years before any heart symptoms, because the smaller arteries in the penis are affected sooner than the larger ones feeding the heart.

What Can Get in the Way

Difficulty getting or maintaining an erection is common and becomes more so with age. About 5% to 10% of men under 40 experience it. By age 40, roughly 22% of men have moderate to complete difficulty, and by age 70, that number reaches nearly 50%. Some degree of erectile change affects about 39% of 40-year-olds and 67% of 70-year-olds.

The causes fall into a few broad categories:

  • Vascular: Anything that reduces blood flow. High blood pressure, diabetes, high cholesterol, smoking, and obesity all damage the blood vessel lining over time.
  • Neurological: Conditions that disrupt nerve signals, including spinal cord injuries, multiple sclerosis, and nerve damage from surgery.
  • Hormonal: Low testosterone or thyroid imbalances can reduce arousal and weaken the erection response.
  • Psychological: Performance anxiety, depression, relationship stress, and general anxiety activate the sympathetic nervous system and suppress the parasympathetic signals needed for erection.
  • Medications: Several common drug classes can interfere with erections. Blood pressure medications (especially thiazide diuretics and beta-blockers) are among the most frequent culprits. Antidepressants, particularly SSRIs, anti-anxiety medications, antihistamines, opioid painkillers, and some heartburn drugs can all have this effect. Even over-the-counter options like diphenhydramine (Benadryl) or pseudoephedrine (Sudafed) may contribute.

Lifestyle Factors That Help

Because erections depend so heavily on blood flow and nerve signaling, the same habits that protect your cardiovascular system directly support erectile function. Regular aerobic exercise improves endothelial health, meaning the lining of your blood vessels produces more nitric oxide. Maintaining a healthy weight reduces the strain on your vascular system and helps keep testosterone levels in a normal range. Limiting alcohol is relevant too: small amounts may reduce anxiety and help with arousal, but larger amounts suppress the nervous system’s ability to trigger and maintain an erection.

Sleep quality matters more than most people realize. Since testosterone production peaks during sleep and the body cycles through multiple erections each night, chronic sleep deprivation can lower both hormone levels and overall erectile health. Managing stress through whatever works for you, whether that’s exercise, therapy, or simply reducing obligations, keeps your sympathetic nervous system from chronically suppressing the parasympathetic signals your body needs to get and stay hard.