Who hasn’t had a delicious milkshake, Popsicle or ice cream cone interrupted by the summertime curse known as a “brain freeze”? The pain starts on the roof of your mouth and within an instant feels like lightning bolts bouncing inside your skull. Then poof! A few seconds later, the discomfort disappears.

Just because the pain caused by a brain freeze, or ice cream headache, is fleeting doesn’t mean it’s any less real. In fact, doctors have an official name for the unpleasant condition — sphenopalatine ganglioneuralgia — but good luck pronouncing it (sfeh-nuh-pa-luh-teen gang-glee-o-nur-al-juh).

So, what’s going on inside your head during a brain freeze?

“You can think of it almost like a cramp,” says Wojtek Mydlarz, director of head and neck surgery at Johns Hopkins Medicine. “When you move too quickly, you might get a little strain or sharp pain.”

Similarly, when we eat too much ice cream too fast, it surprises your body.

“You’re shocking your system. You’re shocking your throat, your palate and your tongue from the cold, especially when it’s hot outside,” says Mydlarz.

In response to the coldness, blood vessels in the roof of your mouth tighten while something known as the trigeminal (try-jeh-muh-nuhl) nerve sends a message to your brain saying that the body needs to turn up the thermostat. The brain responds by sending warm blood to your mouth, loosening the blood vessels there.

When your body recovers from the cold exposure and tightening of blood vessels, “that’s when you get that very sharp headache,” says Mydlarz.

The good news is there are a few tricks for making ice cream headaches go away faster. First, you should put down the tasty treat for a minute, because taking another bite or slurp will make matters worse.

Next, try to press your tongue against the roof of your mouth. Its warmth is thought to help your blood vessels return to normal, essentially turning the brain freeze into a brain thaw.

While it all might seem silly — giving yourself pain over a dessert — there’s evidence that brain freezes are related to more serious conditions. For instance, people who get intense headaches called migraines are also more likely to get ice cream headaches.

Of course, fear of brain freezes shouldn’t keep you from enjoying an ice-cold treat on a hot day. Mydlarz loves a big bowl of coffee-flavored ice cream now and then, and he’s a medical expert. But he says we need to listen to our bodies when they’re trying to tell us something. “Your head is saying, ‘Stop. Slow down. Give me time to adjust.’ ”

Bittel is a freelance journalist who often writes about animals. His children’s book, “How to Talk to a Tiger . . . and Other Animals,” was published in April.