Cavities are primarily caused by a combination of factors, including the presence of bacteria in the mouth, frequent consumption of sugary or starchy foods and drinks, and poor oral hygiene. The bacteria in the mouth feed on sugars from food and produce acids that erode the enamel, the protective outer layer of the teeth.