Cavities are caused by bacteria in the mouth that produce acid, which erodes tooth enamel. Prevent them by brushing and flossing regularly, limiting sugary foods and drinks, and using fluoride.