How does the blood-brain barrier function to protect the brain? Explain its role in preventing certain substances like bacteria or viruses from entering the brain in paragraph form.