When your immune system has studied a pathogen, it can recognize that pathogen in the future and destroying it quicker. This results in you being
immune to that pathogen
. By getting sick yourself you build up
natural immunity.
Sometimes you need to be vaccinated for a pathogen. Vaccines consist of just the antigens of the pathogen so your body can still study it but you won't get sick. When you are actually infected your body can still recognize the ''new'' pathogen and destroy it quickly. This is called artificial immunity.
To be properly protected against certain diseases every population must have a sufficient
vaccination coverage.