Cephalexin is used to treat bacterial infections in many different parts of the body. It belongs to the class of medicines known as cephalosporin antibiotics. It works by killing bacteria or preventing their growth. However, this medicine will not work for colds, flu, or other virus infections.