The process of conferring immunity against a particular pathogen by one of two means: active (e.g., production of antibodies by exposure, such as a pneumonia vaccination) or passive (e.g., transfer of antibodies via breastfeeding).