Metal carbonates react with dilute acids to form salt, water and carbon dioxide gas. Thus, carbon dioxide can be prepared by reacting any metal carbonate with any dilute acid.
Example: Carbon dioxide gas is liberated when sodium carbonate reacts with dilute hydrochloric acid.