Medical effects of caffeine on headaches

Caffeine restricts (narrows) blood vessels. Headaches are (generally) caused by dilated (widened) blood vessels which applies pressure to your pressure/pain receptors. By consuming caffeine, the caffeine restricts the blood vessels thereby reducing, or even eliminating, the headache. I have verified this fact through personal experience and from my local doctor.

Of course, as with any drug, caffeine consumption over a prolonged period of time induces a physiological dependence. Because of this, the effects of caffeine on the blood vessels will not be detectable whenever you drink coffee. So, if you regularly drink caffeine, it will not have the desired effect on your headaches. Once regularly consuming caffeine, your veins will be at their "usual" width, so long as your intake of caffeine continues. To get the desired constriction, you must consume a much larger dose.

However, also due to the effects of addiction (or if you will, the effects of withdrawal), once you stop consuming caffeine regularly, the reverse effects of the drug take place. Thus, when you stop consuming caffeine, the blood vessels dilate. This causes headaches, as tobtoh mentioned. This is, in fact, the reason that people on
"reahbilitation" from caffeine experience headaches for several days after quitting.