The study of how the host defends against invading viruses and bacteria (pathogens), as well as other foreign bodies such as toxins, venom and tissue implants.