A vaccine work by priming the immune system against virus attacks. There are some other vaccines that can work against both bacterial and viral pathogens or even in disease-causing agents.
How Vaccines Work?
By the time when pathogen gets into your body, the immune system is generating antibodies in fighting it off. Depending on the level of immune system you have and also, to how effective the antibodies in fighting pathogens, you might or might not get sick.
In the event that you fall ill on the other hand, there are antibodies that are made will stay in your body and play as watchdog after you recover. In the event that you are exposed to similar pathogen down the road, the antibodies inside you will quickly recognize it and kill the virus that entered your body.
Just an Itsy Bit of the Virus
Vaccines work for this particular function of our immune system. They are made from a partial, weakened or killed version of that pathogen. When you have vaccine, no matter what version of pathogen it has is not plentiful or strong enough in making you sick but, it is more than enough for the immune system to generate the necessary antibody to fight it off.