In order to build immunity to a bacteria only a tiny amount of 'inactivated' bacteria is put into the vaccine. Because the bacteria is dead/inactivated its not able to cause harm to our body but it will still trigger an immune response from the body as it is still recognised as an antigen due to the proteins on its cell membrane. This leads to the production of specific antibodies, which counteract the antigens, which can easily be produced again if the body comes into contact with the active/alive form of bacteria at a later stage. Vaccination is a form of artificial immunity.