As I hope you know if you're reading this, an erection is the result of sexual arousal in men. The penis becomes engorged with blood, causing it to swell, harden, and, for lack of a term with more finesse, stick out. This makes intercourse possible and is vital for reproduction. So here's the layman's guide to what's going on that causes an erection.

Note: This is written to appeal to the average person who's just moderately curious, and so I will avoid using super-specific terminology (I will also not explain the parts of the penis, as it is difficult to understand without diagrams and I believe it's possible to understand the erection process without understanding the details of the anatomy. I will also henceforth try to avoid using the word "understand" three times in a single sentence). If you're really crazy interested in the fine details, there are lots of professional articles out there.

Flaccid State
To understand how an erection happens, it's important to realize what's going on before it. In a flaccid penis, blood flow is minimal, just enough to deliver nutrients (aka keep the thing from falling off). This is because they're controlled by muscles, which usually stay pretty contracted. The muscles (which are smooth muscles, meaning that they are controlled involuntarily, like muscles in your stomach and intestines) contract more in cold weather (hence shrinkage).

Stimulation and Erection
You might have heard before that the biggest sex organ is actually the brain. Not surprisingly, then, the way an erection usually* starts is with neurotransmitters (chemicals the brain uses to send signals to the body). Many kinds of stimulation can cause them to be released, including physical and mental, both conscious and non-conscious. Whichever way you get turned on, these chemicals cause those muscles we just mentioned to relax. Remember, if contracting these muscles shrinks the penis (like in the cold), then relaxing them is going to contribute to the opposite. Keeping them contracted keeps blood vessels small, so relaxing them allows the vessels to widen. A quick note for anyone who hasn't studied anatomy since grade school: arteries carry blood away from the heart to the rest of the body - remember Arteries Away - and veins carry blood back to the heart.
More on these widening arteries - the penis contains three regions of erectile tissue, which is packed with a special type of blood vessel. These particular vessels are full of little pools. The dilation from muscle relaxation lets more blood in, which collects in these pools. While the arteries are widening, the veins are being compressed, which keeps blood from easily leaving the penis - so it stays gathered in the pools of the arteries. The compression is due to the pressure caused by the engorged arteries.
It's worth noting that the head of the penis (the glans penis) stays a little squishy. This is because the veins aren't as compressed in the head, because most of the swelling action is taking place in the shaft, aka body, of the penis.

Ejaculation
After an erection and subsequent sexual stimulation comes (no pun intended) ejaculation. Ejaculation (and orgasm, for that matter, although I won't delve into that wonderful and mysterious phenomenon here) are some of the least understood aspects of male sexuality. However, it is generally agreed that there are several stages, and different sources state different numbers and names for them. Encyclopedia Britannica, for example, says there are two: emission and ejaculation proper (because this is very classy business, after all), but some sources describe three, calling the closure of the bladder neck (to prevent semen from entering the bladder) its own stage. Regardless, ejaculation essentially happens as follows:
First, the semen are moved from the seminal vesicles (basically, the place in the testicles where they sit around waiting to be spat up) into the base of the penis. It's somewhere around this point that a guy feels like his orgasm is inevitable. This is also the point at which ejaculation becomes unavoidable. Next comes the bladder neck closure, which is necessary because semen leaves the body through the urethra, which is connected to the bladder. This involuntarily blocks off the bladder so that semen can't go backwards into it.
Finally, there is the propulsion stage, in which the muscles at the base of the penis contract at a regular interval (a little less than a second apart) to cause semen to be released in several spurts. The exact physiology of this stage has been debated, and it used to be thought that during the emission stage, the semen created a pressure chamber that was then suddenly released. Research has revealed, however, that no such chamber is created, and the amount of semen in any given ejaculation is too small to create the pressure necessary for a powerful ejaculation.

*filoraene has brought to my attention that I failed to account for erections caused without stimulation - namely, "morning wood," or an erection a guy has when he wakes up. Men actually tend to have multiple erections throughout sleep, especially during REM sleep (when the brain is most active). There are different hypotheses about exactly what causes it. Several sources say it's just the body's way of making sure everything is working, although personally I think that putting it that way is very vague and uninformative. A better answer is that regular erections occur for a number of reasons: the brain, being very stimulated during REM sleep, releases the neurotransmitters necessary to cause an erection (regular sexual arousal, but while asleep); or, during a period of deep relaxation, the muscles relax and subsequently, the penis fills with blood; or, a better way to restate the first suggested reason, having regular erections ensures that the penis receives plenty of nutrients and stays healthy.

Log in or register to write something here or to contact authors.