Active immunity develops either through natural exposure to a pathogen or through vaccination. When the immune system encounters a foreign antigen, such as a toxin, it stimulates the production of antibodies and memory cells. These memory cells are crucial for rapid and effective responses upon subsequent exposures to the same antigen, providing a basis for long-term immunity.