Galvanic corrosion occurs when dissimilar metals are in electrical contact in the presence of an electrolyte. Corrosion of the more noble metal is inhibited, while that of the less noble is accelerated.
This is explained by the different electrode potentials of different metals. Lower-nobility metals, having lower electrode potential, act as an anode, attracting electrons, dissolving into the electrolyte, and depositing on the more noble metal (the cathode). The rate of dissolution depends on the difference of nobility: the electromotive force of such a reaction is defined by the potential of the anode subtracted from that of the cathode.
The galvanic series arranges metals and semi-metals by their electrode potential in Earth's most common electrolyte--seawater. Examples of more noble metals include graphite, gold, and silver; lower-nobility metals include aluminum, zinc, and magnesium.
Zinc in particular is often sacrificed to control or exploit galvanic corrosion. Cheaper household batteries, or galvanic cells, generate voltage via the rapid dissolution of zinc relative to manganese oxide within an alkaline solution. Rechargable batteries utilize metals, such as lithium, that can be re-constituted with reverse current (the imperfection in this process partially explains why rechargeable batteries develop "memory.") Submerged and buried metal structures usually feature large zinc anodes; one example is the zinc rod mounted to the underbelly of a boat. Likewise, the zinc plating on galvanized screws and bolts lengthens the life of the underlying, stronger steel.