To start we need to ask: what causes an infection? The answer is a pathogen, which is a microbe that causes disease. These can be bacteria or viruses. A vaccine contains dead or inactive pathogens that are injected into the body. These pathogens have specific antigens on their surface that the immune system recognises as being different to antigens on cells in the body. White blood cells release antibodies that are complementary (can fit onto) the pathogenic antigen. Once the antibodies have attached to multiple pathogens they form clumps. White blood cells engulf the pathogens and the process of phagocytosis occurs. This is the primary (first) infection so the body responds slowly- taking around 10 days to produce lots of antibodies. As the pathogen is dead/inactive, the person doesn't actually develop the disease. White blood cells will produce antibodies rapidly when exposed to the pathogen a second time, so will avoid infection. This person is now immune.