Vaccines are made in a few ways - from live attenuated pathogens, inactive pathogens or by using new technologies such as mRNA. Pfizer/BioNTech and Moderna have developed mRNA vaccines for COVID-19 in 2020. A few weeks after a vaccine is administered, - the body produces T lymphocytes [T cells] and B lymphocytes [B cells]. B cells produce antibodies that attack antigens. T cells attack cells in the body that have been infected.
Over time, these “memory” T cells and B cells will die off but enough will survive so that if the body sees a virus enter it, the remaining memory T cells and B cells will go into very rapid action and produce new T cells and B cells to kill the invading pathogen.
For a real explanation: