The main function of antibiotics is to treat bacterial infections. They do this either by inhibiting the growth and replication of the bacteria or by interrupting the bacterial cell wall formation, thereby killing the bacteria quickly. When used prior to a surgical procedure, antibiotics can prevent an infection from occurring.