Cefazolin is used to treat bacterial infections in many different parts of the body. This medicine is also given before certain types of surgery to prevent infections. Cefazolin belongs to the class of medicines known as cephalosporin antibiotics.