A vaccine is a chemical preparation that are usually made up of microorganisms, viruses, or fragments of either. In all the cases the purpose of a vaccine is designed to introduce an antigen into an immune system and teaches the system to fight a virus or pathogen. Once exposed to the vaccine the immune system then begins to create antibodies that can then combat the virus. Then if a person really contracts a virus, then their immune systems will be prepared to combat it.
History and specifics
In 2266, Dr. Leonard McCoy was able to vaccine to a disease that originated from a life prolongation project on Juram V. While the disease allowed the children of the planet to live for centuries until they entered puberty, all the adults died within a few days. (TOS episode: "Miri", TOS novel: The Cry of the Onlies)
By the 24th century, Federation medicine had discovered a form of vaccine for almost all diseases and illnesses that they had encountered. However, not all diseases had a vaccine readily available so research still continued. In 2365, an outbreak of plasma plague in the Rachelis system led the USS Enterprise to transport samples of the most deadly diseases in the Alpha Quadrant to Science Station Tango Sierra, in the hopes that the scientists there could perhaps develop a vaccine. (TNG episode: "The Child")