What they are and what causes them.
The terms brain freeze and ice cream headache refer to the same painful headache many people get when quickly eating something cold. The pain is caused by the rapid cooling of the roof of the mouth, which is close to the sphenopalatine nerve, a section of an extensive bundle of nerves running from the face up into the brain.
When this nerve gets cold, it fires off a danger signal that the entire head is about to become chilled and warns the vascular system to start pumping more blood to the brain to keep it warm. Vessels open up and the sudden in-rush of warm blood causes a painful sensation, which lasts anywhere from 30 seconds to 2 minutes. By that time the body has rewarmed the sphenopalantine nerve and the blood flow to the brain reduces to normal levels, stopping the pain.
The source of the pain has been described as being similar to that resulting from sticking hands chilled in winter into a bucket of warm water. The sudden increase in blood flow and associated expansion causes pain.
One third of all people are statistically susceptible to brain freezes. They more often caused by eating ice cream than drinking an iced beverage because ice cream is colder than ice. Also, they are much more common when the weather is warm than when it's cold, suggesting that it's the rate or amount of temperature change that's important.
Brain freezes are called "referred pain" because the pain occurs in a location (the brain) that's different than the location of the stimulus (the roof of the mouth.)
The quickest way to relieve a brain freeze it to take a drink of warm water and hold it against the roof of your mouth. Since they are over so quickly anyway and it's unlikely that you're going to be holding a cup of hot water in one hand at the same time that you are holding an ice cream cone in the other, the next best thing to do is press your tongue against the roof of your mouth to rewarm the nerve.
Prevention is simple: eat and drink very cold foods slowly.