What happens when you have an erection is a remarkable and complicated process.
The vascular system
A problem with the penile vascular system is the most common physiological cause of erectile dysfunction (ED). When you are relaxed and open to mental and physical stimulation, blood flow increases to your genitals; specifically, to your penis. A number of physical, psychological, relational, and situational factors can interfere with this natural functioning. Common physical causes of ED include - in the order of frequency - high blood pressure, side effects of some medications, vascular disease, high blood sugar (poorly controlled diabetes), and vascular injuries.
Psychological and relationship stresses can impact your body and cause or sustain a sexual dysfunction like ED. Common psychological factors are anticipatory or performance anxiety, distraction, anti-erotic thoughts, being a passive spectator, and depression. Relational factors that subvert erectile function include emotional alienation, miscommunication, unresolved conflict, lack of attraction or desire, coercion or intimidation, anger, frustration, worry about your partner's anxiety or sexual discomfort, not feeling subjectively turned on, shyness, or inhibition. Situational factors that cause dysfunction include lack of privacy, trying to have intercourse when minimally aroused, and fatigue. Appreciate that these same factors can impede your partner's arousal, excitement, and orgasm.