Many of us at some point during our lives have had an infectious disease such as influenza. Knowingly or unknowingly you are exposed to someone that is infected. You feel fine for a few days and then you begin to feel a little off. You gradually feel worse and eventually you may feel so ill that you can not function normally and you stay in bed. After a few days of misery the symptoms gradually begin to fade away and you slowly return to your normal routine. If other members of your family became sick during your illness you do not worry about being around them - you are now immune to this disease.
Wouldn't it be nice to have that immunity without having to suffer through the disease? This is what vaccination does.
Most vaccines contain the agent that causes the disease in an inactivated form. When it is injected into the body, the immune system recognizes the material in the vaccine as foreign (not a normal part of the body) and responds to it in the same way as it would if the body were infected with the virulent agent - making antibodies against it. Later on if the body is exposed the to the actual disease causing agent the immune system is able to respond quickly enough to wipe it out before it causes disease.
In many vaccines the infectious agent is killed, either by heat or chemical treatment, during the manufacturing process. Because dead organisms do not tend to provoke as strong an immune response as live ones, it is usually necessary to use adjuvants (chemicals that increase the immune response). This has the advantage that it is impossible for the vaccine to revert to virulence and cause the disease, but it brings with it the disadvantage that the immune response may not be as protective as the immune response against a live organism.
Other vaccines contain the live agent (virus or bacteria) that causes causes the disease in an attenuated (weakened) form. Using a live agent provokes an immune response that is more effective than the immune response provoked by a killed organism . One drawback to using a live agent is that in some cases the organism is able to revert to virulence and actually cause the disease.
Some vaccines only contain one part of the organism that causes the disease. An example of this would be the tetanus vaccine, which contains an inactivated form of a toxin secreted by the bacteria (Clostridium tetani) that causes tetanus. This vaccine stimulates the immune system to produce antibodies against the toxin. Vaccination against tetanus does not provide protection against infection with Clostridium tetani, but it does provide protection against the effects of the toxin that the bacteria secretes.
There are also a few newer vaccines that do not actually contain any of the disease causing agent. It is now possible to put a few selected genes from the disease causing organism into a viral vector. The viral vector infects cells around the vaccination site and the infected cells produce part (but not all) of the structural components of the organism that is being vaccinated against. This approach has the advantage that the immune response is closer to what it would be with a live vaccine, while at the same time (because the disease causing organism is not actually present) there is no chance of the vaccine reverting to virulence and causing the disease.
There is much more to the way in which vaccines prevent disease than can be presented in this brief overview. A good immunology textbook from your local library could provide in depth information about this fascinating subject.