Men start noticing erection from the onset of puberty. It will come as a surprise to many that the source of erection is not the penis, but the brain. The penis has two cylinder-shaped chambers that are made up of a network of blood vessels, tissues, and open pockets. Each chamber has an artery and various veins that carry blood in and out of them. Nerves help in communicating messages to and from different parts of the body.
On physical or mental provocation, the brain prompts a hormonal response. This releases the chemical, nitric oxide, which causes the arteries to soften up and the veins to close down. The relaxed arteries facilitate more blood flow into the penis where it is trapped in the chambers. The penis expands and becomes erect. When the brain stops sending signals of arousal, the hormonal response ends, and the penis becomes flaccid.
When the penis consistently fails to reach and maintain an erection, long enough for you to have sex, then this becomes a case of Erectile Dysfunction or ED. Due to social stigma or plain embarrassment, most men fail to tell their physician about their ED. Though erectile dysfunction is seen more as men age, it is also prevalent in men of middle age.
Around 30 per cent of men in the age group of 40 to 50 are known to suffer from ED. However, 80 per cent or more men suffer from ED when they reach 70 or beyond . Studies have proved that cardiovascular diseases (CVD) and diabetes are the main underlying organic reasons for ED.
Around 50 per cent of the men in the age groups of 40 to 50 suffer from ED due to CVD alone, while the percentage of men in the same age groups suffering from ED due to diabetes alone is around 60 per cent . The probability of men suffering from ED due to CVD raises to approximately 70 per cent as they reach the age of 70, and the percentage of ED is around 90 for the men in the same age group due to diabetes alone. 
The percentage of ED in men suffering from diabetes depends on a lot of factors like the age, the period of diabetes, obesity, smoking history, how well the diabetes is in control, and other complications arising due to the presence of diabetes. Erection depends on the nervous system and blood circulation. An imbalanced blood sugar level-that often happens in diabetic patients-damages the nerves and the blood vessels. When blood sugar levels are high, nitric oxide is not produced optimally. When there is a low level of nitric oxide, there is not enough blood flowing to the penis to keep an erection.
Though there are other known reasons for ED like stress, depression, lack of sleep, substance abuse, certain surgeries and diseases, diabetes by far is one of the major factors resulting in ED. If you find yourself suffering from ED, consult your physician immediately.
Reference: http://s3.amazonaws.com/zanran_storage/archinte.ama-assn.org/ContentPages/97541805.pdf#page=4 pg 216 figure 1 and 2