A cavity is formed by bacteria present in your mouth. When plaque is formed around the tooth due to poor oral hygiene, bacteria degrade carbohydrates in plaque and release acidic content. The tooth is a mineralized structure and an excessively acidic diet causes demineralization and leads to cavity formation.