The only thing I can add to the above fine answers, is that once the antigen (piece of bacteria/virus/fungus) is picked up by "scavenger" / Antigen Presenting Cells that are found all over your body, skin, mucous membranes etc - they are taken to immune organs such as the lymph nodes, thymus, spleen. They present the antigen (from the vaccine) to the T cells that reside there. The T cells will then become "activated", start to replicate, forming "Effector T" cells which fight the disease, but also "Memory T" cells. Its these memory cells that stay in the immune organs just hanging round waiting for the body to come into contact with the same antigen again. When that happens they start to divide rapidly into effector cells, so the infection is dealt with very quickly because the body doesnt have to "relearn" the second time!