If you suffer from migraines, it might be time to kick that coffee habit.
Researchers have found that drinking three or more cups a day substantially increases the risk of an attack.
The study tracked 98 sufferers of "episodic" migraines - defined as having the debilitating headaches on up to 14 days a month.
They found that drinking up to two cups of coffee or other caffeinated drinks made no difference to their chance of a migraine.
But when they drank three cups, the risk of having an attack the same day went up by 40 per cent. If they had five cups, it rose by 161 per cent. Study leader Elizabeth Mostofsky, of Harvard University, said: "Drinking one or two caffeinated beverages in a day does not appear to be linked to developing a migraine but three or more servings may be associated with higher odds of developing a headache."
More than eight million Britons - three-quarters of them women - suffer migraine attacks, which involve dizziness, nausea and headaches. Episodes can last from four to 72 hours.
The problem affects more people than diabetes, asthma and epilepsy combined, and is the sixth most common cause of disability in the world.
The researchers, whose findings are published in the American Journal of Medicine, said the impact of caffeine on migraines is complex because it depends on dose and frequency. And while it may trigger an attack, it can also have a painkilling effect.
Participants completed diaries twice a day for six weeks reporting on the frequency and severity of migraines and their intake of caffeinated drinks.
Fellow researcher Dr Suzanne Bertisch said: "There have been few studies on the immediate risk of migraines with daily changes in caffeine intake."
The cause of migraines is not fully understood. They are thought to occur when abnormal brain activity affects nerve signals, chemicals and blood vessels in the brain. Other potential triggers include stress, anxiety, depression, poor-quality sleep or hormonal changes during the menstrual cycle.
Dehydration, drinking too much alcohol and missed meals may also cause them.
Basic painkillers are often an effective treatment, although sleeping or lying down in a dark room are also recommended techniques.