A cavity is caused by an accumulation of bacteria in your oral cavity. Once the bacteria congregate they eat the sugars in your mouth as food. Once they consume the simple sugars they excrete acid into your mouth and onto your tooth surface lowering the ph in your mouth. This decrease in ph causes the outer layer of your tooth (enamel) to be eaten away forming a cavity. Once a cavity is formed the bacteria needs to be removed and a filling needs to be placed to repair the lost tooth structure. If the cavity is too large it might need alternative dental treatment for it to be repaired.