Immunity refers to the ability of an organism to resist infection by acting against the disease-causing microorganisms. This is enabled by the action of antibodies against the pathogen (disease-causing organisms like bacteria, virus, etc) or sensitization of white blood cells (WBCs), which rise to fight against infection in the body.
Immunity is of several types. It may be present since birth (innate immunity) or acquired at a later stage of life after exposure to a pathogen or by direct administration of antibodies (acquired immunity). It may be natural (acquired by exposure to the disease-causing agent) or synthetic (acquired by vaccination against a disease). It is also categorized as active or passive. In the former, the vaccine is administered to the individual and the latter constitutes the injection of antibodies directly.
Infection once caused easily spreads from person-to-person by direct contact or indirect contact through the belongings of the diseased. Infection may also spread through air, droplets and other mediums.
So, an individual with better immunity against diseases not only protects himself/herself but the community as a whole, as per the concept of herd or community immunity.
Other than vaccination against diseases and a live encounter with disease-causing organisms, you can also improve your immunity by taking care of your diet and a lot of good habits, which we'll discuss ahead.