The protection someone gains from having an infection (called natural immunity) varies depending on the disease, and it varies from person to person. Since this virus is new, we don’t know how long natural immunity might last. Current evidence suggests that reinfection with the virus that causes COVID-19 is uncommon in the 90 days after initial infection.
Regarding vaccination, we won’t know how long immunity lasts until we have more data on how well the vaccines work.
Both natural immunity and vaccine-induced immunity are important aspects of COVID-19 that experts are trying to learn more about, and CDC will keep the public informed as new evidence becomes available.