Vaccines contain weakened or inactive parts of pathogens, which stimulate the immune system to produce antibodies specific to those pathogens. These antibodies help the body recognize and fight off the actual pathogen if encountered in the future. By training the immune system to respond effectively, vaccines provide immunity against diseases without causing illness.