I found this explanation of how vaccines work at the cellular level pretty fascinating. Long, but very well done.
"Your immune system is a pretty complex integrated system of cells, tissues and organs that protect your body from both internal and external threats. At the cellular level, there’s the innate immune system and the adaptive immune system. The innate immune system is the first responder and a blunt instrument - always ready, acts quickly, destroys things, but is non-specific. The adaptive immune system is the more sophisticated part - it works more slowly, but it has two big advantages: it is specific (responds to particular threats) and it has memory. The adaptive immune system is the part that makes specific antibodies that neutralize what it’s fighting against. (*This response time is also why you are not immediately protected after getting a vaccine - it can take a couple of weeks for your adaptive immune system to make those antibodies. Some vaccines, like the COVID vaccines, also take more than one dose to really get a strong response from the immune system. Antibodies can also wane, which is why we get boosters of some vaccines.)
The way most traditional vaccines train your adaptive immune system to recognize and produce antibodies against specific threats is by using weakened or dead versions of the virus/bacteria. The immune system would recognize them as invaders and produce antibodies - like a trial run. When later faced with the actual threat, the memory of the adaptive immune system kicked in and those antibodies were ready to go and neutralize the threat.
The Moderna and Pfizer vaccines are a new kind of vaccine. They both use messenger RNA (mRNA) to stimulate the immune system to make antibodies. mRNA are instructions for making proteins. Within your cells are tiny structures called ribosomes that can “read” the mRNA instructions, and then make the protein. (I’ll point out here that ribosomes are NOT in the nucleus of the cell - they’re in the cytoplasm. Our DNA is in the nucleus of the cell. Concerns that the vaccines will somehow affect our DNA are not valid, as mRNA doesn’t get into the nucleus).
Both vaccines are basically tiny snippets of mRNA encased in a protective fat bubble. The mRNA is code for the spike protein found on the surface of the coronavirus - not the code for the whole virus, just that protein. When injected, the mRNA is taken up by cells, the ribosomes read the instructions, produce the little spike proteins, and they’re pushed to the surface of the cell.
At this point, the adaptive immune system recognizes that these weird little proteins don’t belong, and starts making antibodies. What antibodies do is neutralize the protein and prevent the virus from infecting a cell. If you think about a lock and key, if you put a wad of gum around a key, it couldn’t unlock a lock anymore. The antibodies function as the gum - preventing the virus (key) from infecting (unlocking) the cell (lock).
After a few days, the snippets of mRNA are broken down in the cell, but by that point, they’ve done their job - the adaptive immune system has been trained and now has antibodies ready to neutralize the coronavirus (specifically that spike protein) in case it ever gets in.
This is how vaccines specifically protect you from getting infected - or, if you do get infected, it will be mild, as most of the virus particles will be neutralized by antibodies. This is also why it’s possible to still be a carrier and not get infected yourself - you could sniff in some virus particles, they could hang out in your nose, and you could sneeze and have those particles carried back out into the world on droplets. It’s why people still need to practice hand hygiene and mask wearing, even if they’ve been vaccinated.
Both vaccines are highly effective - Pfizer 95%, Moderna 94.1%. Those numbers come from the clinical trials - they split the groups into a vaccine group and a placebo group, and then watched what happened over the following couple of months. In the Pfizer study, something like 162 people in the placebo group got COVID during that time period, while only 8 in the vaccine group got COVID - hence, 95% effective. It’s important to note that it’s not 100% effective - for one thing, people’s immune systems differ! Vaccines depend on your immune system really mounting a strong defense. In the elderly, the immune system just isn’t as strong, and therefore, it often takes more to provoke a robust response (it’s why elderly are given higher dose flu vaccines - their immune systems need that extra prompt to do their work)"