When you eat fermentable carbohydrates - or foods that contain sugar - the bacteria in the mouth use the sugar for fuel and produce acid as a waste product.  This acid causes the pH in your mouth to lower to a level that can dissolve enamel in less than 5 minutes.  It takes 20 minutes for the pH to naturally return to a normal and neutral level.  


If the acidity in the mouth frequently occurs, the enamel crystal of the tooth will begin to demineralize and lose calcium.  If this process continues, a cavitation or cavity will occur in the tooth.  


A cavity is most likely to form in "nooks and crannies" of teeth - where bacteria can reside and are less likely to be brushed or flossed away.