Anodes protect your underwater metals from galvanic corrosion. Anodes are sacrificial metals. They are more active in giving up their electrons and will corrode before your prop, shaft, thru hulls, struts, strainers, sail drives, etc.  For example, two metals (such as a stainless shaft and bronze prop) in electrical contact will create a charge, similar to a battery, and deteriorate your boat’s valuable underwater metals. We replace these sacrificial anodes so your valuable metals are not subject to corrosion.  
There are different metals used as anodes: Aluminum anodes are versatile in both salt and fresh water. Zinc is still used everywhere but is ideally used in salt water.  Magnesium should only be used in fresh water. Many factors affect the timing of anode replacements such as your marina, your boat, boats around you, anode size and type.
Generally speaking, boats moored in salt water should have their anodes inspected and replaced every 6 months.