As SciAm's Ferris Jabr explains in the video up top, the short answer is: nociceptors. Many animals have these sensory neurons. Some animals have weird ones. Take naked mole rats, for example — NMRs have mutated sodium channels that limit physiologically "normal" nociceptor firing, thereby blunting sensations of pain
Pretty much everyone has experienced brain freeze (also known as ice cream headache) at one point or another. And while scientists have learned a fair bit about what might cause brain freeze, there's still much we don't understand about what gives rise to this painful phenomenon.