Harvard Health Publications\\Harvard Medical School(Harvard Health Publications\\Harvard Medical School )

Q: Is pneumonia contagious?

A: Yes, most types of pneumonia are contagious. Pneumonia is an infection of the lungs. Many different infectious agents can cause pneumonia. Most often it is caused by bacteria and viruses.

When a person with bacterial or viral pneumonia coughs, some of the bacteria and viruses spread out into the air around them. If another person nearby breathes in the air, the bacteria or viruses can then enter their lungs.

Fortunately, our lungs have many defense mechanisms to recognize when bacteria or viruses have entered them. Most of the time, when bacteria or viruses enter our lungs, they get killed and never cause an infection in our lungs. But sometimes they do.

How do you avoid catching pneumonia?

Most people with pneumonia don't pass it to the people around them. But here are some tips to be on the safe side.

Avoid people who are coughing. Most people who cough do not have pneumonia. They have infections of the nose, throat, sinuses or breathing tubes, but you can catch an infection from them, too. When someone near you coughs or sneezes, turn your head away and don't take in a breath until your head is pointing in a different direction.

Some infections, including the bacteria and viruses that can cause pneumonia, can be passed on a person's hands, too. So if you shake hands with someone who is coughing and might have pneumonia, wash your hands with soap and water or disinfectant hand gel before you touch your nose, mouth or eyes.

Anthony Komaroff, M.D., is professor of medicine and editor-in-chief of Harvard Health Publications at Harvard Medical School. Dr. Komaroff also is senior physician and was formerly director of the Division of General Medicine at Brigham and Women's Hospital. Dr. Komaroff has served on various advisory committees to the federal government, and is an elected Fellow of the American Association for the Advancement of Science.

More from MSN Health & Fitness: