We all know that eating a lot of sugary foods results in cavities, but most of us don’t know exactly how it happens. In a TEDEd lesson by Mel Rosenberg, a narrator explains that tiny microbes living in our mouths use sugar as an energy source and create acid as a byproduct of that process. The acid corrodes enamel and the tooth. We pick up those rude, acid-producing microbes shortly after we are born, a gift from our dear parents.

According to the lesson, cavities have been part of the human condition for a long time — ancient humans’ teeth had holes in them and cavemen used sharpened flints to remove rotten teeth as early as 14,000 years ago, the lesson explains. They also used beeswax to plug their cavities.

And it turns out it’s not just straightforward sugary foods that put our teeth in a rough spot; cavemen, who didn’t have licorice and chocolate bars, got their cavities from eating foods like nuts, grains and vegetables, after their saliva turned the carbohydrates into sugars.

Sweets, the food most closely associated in the public consciousness with cavities, became a much larger cause of tooth damage after the Industrial Revolution, when refined sugar became cheaper and more accessible.

Watch the full lesson for more information: