2HCl + Mg → H2 + MgCl2
In this reaction, hydrochloric acid acts as an acid, donating hydrogen ions (H+) to magnesium, which acts as a base. The hydrogen ions combine with the electrons released by magnesium atoms to form hydrogen gas. The magnesium ions then combine with the chloride ions from hydrochloric acid to form magnesium chloride.
The reaction between hydrochloric acid and magnesium is a classic example of an acid-base reaction, where an acid and a base react to produce a salt and water. In this case, the salt formed is magnesium chloride, and water is not produced as a byproduct.