You've probably heard it all your life: Eating sweets will rot your teeth. But while a diet high in sugar certainly promotes the formation of cavities (as well as other medical problems, such as obesity), sugar itself isn't the real culprit behind tooth decay.

Dental cavities — also known as caries, the Latin word for "decay" — are formed when bacteria living in the mouth digest carbohydrate debris left on the teeth after you eat. Such debris might include the refined sugars found in cookies, candy and other treats, but can also come from healthy foods like whole grains, vegetables and fruits.

When digesting these carbohydrates, bacteria in your mouth produce an acid that combines with saliva to form that nasty stuff your dentist warned you about: plaque.

It's plaque — not sugar — that leads to tooth decay. Plaque starts building up after every meal, and if it isn't brushed away frequently, it can erode the hard, outer enamel of a tooth, resulting in tiny holes in the tooth's surface. These holes mark the first stage of cavity formation.

And those tiny holes can do a lot of damage if left untreated. Eventually, the acid and bacteria in plaque can eat through the other layers of your teeth, as well — from the softer layer of teeth under the enamel, known as dentin, to the third layer (the pulp), which contains your teeth's blood vessels and nerves. Cavities affecting the pulp of a tooth, as well as the bone supporting tooth, can cause severe toothaches, sensitivity, pain when eating and abscesses in the mouth.

Ultimately, sugar is just one of many carbs that can land you in the dentist's chair, but that doesn't mean you should trade in your apples for candy corn just yet. 

The way you consume food is just as important as the kinds of food you eat. For example, chugging a can of soda actually does less damage to your teeth than sipping on a soda throughout the day, because the acid created by mouth bacteria sticks around for 30 minutes after you eat or drink. So every time you munch another chip or take a sip of soda, you restart the plaque-production clock and increase your risk of developing cavities.