Tooth decay is caused by certain types of bacteria that live in your mouth. When they stick to the film on your teeth called dental plaque, they can do damage. The bacteria feed on what you eat, especially sugars (including fruit sugars) and cooked starch (bread, potatoes, rice, pasta, etc.). Within about 5 minutes after you eat, or drink, the bacteria begin making acids as they digest your food. Those acids can break into the outer surface of the tooth and melt away some of the minerals. Your spit can balance the acid attack if they don’t happen very often.
However if: 1) your mouth is dry,2) you have a lot of these bacteria, or 3) your snack frequently; and then acid causes loss of tooth minerals. This is the start of tooth decay and leads to cavities.