In most cases, infections are contagious for a few days before symptoms appear and for a few days after. The exact length of time a person is contagious depends on the type of microorganism causing the infection.
Some forms of pneumonia, such as pneumonia caused by mycoplasma, remain contagious for several weeks. If a person has pneumonia, they should speak to a doctor about how long the infection will be contagious.