How do vaccines help protect against viruses and diseases?

How do vaccines help protect against viruses and diseases?