Metals corrode faster when in electrical contact with a more noble metal in the presence of an electrolyte.
Under these three conditions galvanic corrosion occurs. The less noble metal dissolve into the electrolyte. The more noble metal’s corrosion is inhibited. Former becomes an anode, latter a cathode.
Alloys and other electrically conductive materials like carbon fiber (graphite) are also subject to galvanic corrosion.
Measures to prevent galvanic corrosion are analogous to the causes: use similar metals, electrical isolation and moisture sealing.
Metals are “similar” when their electropotential difference is small (<250mV). This difference can be looked up in galvanic series charts.
For example, cadmium-plated fasteners in aluminum alloys have little galvanic corrosion potential. Similarly, stainless steel fasteners in carbon fibers (graphite) exhibit little potential.
Having more mass in the less noble metal mitigates the effects of galvanic corrosion. For example, stainless steel screws impact big aluminum alloy structures far less than stainless steel structures would impact aluminum alloy fasteners.
Electrical isolation is an effective strategy as well. With carbon fiber parts it is common practice to add a layer of fiberglass in areas of contact with other metals. Alternatively a layer of primer is often used on nutplates in carbon fiber parts.
Parts that can be effectively sealed from moisture are also safe from galvanic corrosion.