When does an acid react to produce carbon dioxide?

Acids react with carbonates or hydrogencarbonates to liberate carbon dioxide gas. Eg: Acid like hydrochloric acid (HCl) reacts with sodim hydrogencarbonate (NaHCO3) to produce sodium chloride(NaCl), water(H2O) and carbon dioxide(CO2).