According to the Human Illnesses and Behavioral Health website, most viral infections clear up in a matter of days or within a few weeks. This happens because the immune system typically reacts to the virus and removes it from the system. Some viruses cause latent infections that persist for years.
Examples of viruses that cause latent infections include herpes and Hepatitis B and C viruses, according to this source. HIV is another virus that causes latent infections. Such infections may exist without producing any symptoms until years after the infection occurs. In other cases, the infected person recovers from an acute attack of the illness and lives without symptoms until the symptoms return after a period of time.