There are generally dead or weak pathogens present in the vaccine.They enter our body and trigger our immune system.The immune system is fooled by those pathogens and produce antibodies against them which remain in the body and are useful when the pathogens really attack our body.