On a good day, your teeth can chew through tough steak and split hard candy into pieces without you feeling a thing. But sometimes, something as simple as slurping a frosty milkshake can send a shock through your tooth that feels even more painful than stubbing your toe.

According to Live Science, that sensitivity is a defense mechanism we’ve developed to protect damaged teeth from further injury.

“If you eat something too hot or chew something too cold, or if the tooth is worn down enough where the underlying tissue underneath is exposed, all of those things cause pain,” Julius Manz, American Dental Association spokesperson and director of the San Juan College dental hygiene program, told Live Science. “And then the pain causes the person not to use that tooth to try to protect it a little bit more.”

Teeth are made of three layers: enamel on the outside, pulp on the inside, and dentin between the two. Pulp, which contains blood vessels and nerves, is the layer that actually feels pain—but that doesn’t mean the other two layers aren’t involved. When your enamel (which isn’t alive and can’t feel anything at all) is worn down, it exposes the dentin, a tissue that will then allow especially hot or cold substances to stimulate the nerves in the pulp. Pulp can’t sense temperature, so it interprets just about every stimulus as pain.

If you do have a toothache, however, pulp might not be the (only) culprit. The periodontal ligament, which connects teeth to the jawbone, can also feel pain. As Manz explains, that sore feeling people sometimes get because of an orthodontic treatment like braces is usually coming from the periodontal ligament rather than the pulp.

To help you avoid tooth pain in the first place, here are seven tips for healthier teeth.

[h/t Live Science]