Your immune system learns by exposure: the first time it meets a germ it improvises slowly, but afterward it keeps specialized memory cells that recognize that specific invader and respond in hours instead of days. A vaccine delivers a harmless version or piece of a pathogen — an inactivated virus, a protein, or genetic instructions to make one protein — so your body builds that memory without having to survive the real disease first.
This is why vaccine side effects (sore arm, mild fever) are usually the immune system working as designed, not the disease itself. And it's why some vaccines need boosters: memory can fade, and some pathogens mutate their outer proteins so last year's memory no longer matches — the reason flu shots are reformulated annually.
In 1796 the English physician Edward Jenner tested a piece of folk knowledge: milkmaids who caught cowpox, a mild disease, seemed never to get deadly smallpox. He deliberately inoculated an eight-year-old boy, James Phipps, with material from a cowpox sore, then later exposed him to smallpox — and the boy didn't get sick. Jenner had no theory of immune memory (germ theory itself was almost a century away), but he had discovered that a harmless relative of a disease could confer protection against the deadly one. The Latin for cow, vacca, gave the technique its name. Nearly two centuries later, in 1980, a global vaccination campaign let the World Health Organization declare smallpox the first human disease ever eradicated.