Cavities are caused by the bacteria in your mouth turning the sugars and carbohydrates in food into acid. This acid then attacks the enamel of your teeth, which acts as a protective layer.