A vaccine contains weakened bacteria or viruses and is injected into the body. The body responds by attacking said bacteria/viruses. By attacking, the white blood cells learn how to create antibodies which can be used for the next time the viruses or bacteria are in the body. It creates an immunity to the sickness until the virus or bacteria evolves at which point, you need another vaccine.