Pneumonia can be caused by bacteria, viruses, or sometimes fungi, and the cause matters because treatment is different for each
When you have pneumonia, your lungs fill with fluid or pus, making it hard to breathe and get oxygen into your blood. The cause—bacterial, viral, or fungal—determines what your doctor will prescribe. Bacterial pneumonia is treated with antibiotics. Viral pneumonia is not, because antibiotics do not work against viruses; your body's immune system has to fight it. Fungal pneumonia is rare and requires antifungal medication. Your doctor cannot always tell which type you have just by listening to your chest or hearing your symptoms, so they often order a chest X-ray or blood tests to narrow it down.
Key Takeaways
- Bacterial pneumonia responds to antibiotics; viral pneumonia does not, so identifying the cause changes your treatment plan.
- A chest X-ray shows pneumonia is present but usually cannot say whether it is bacterial or viral.
- Blood tests and sputum cultures (a sample of mucus you cough up) can help your doctor identify the cause, though results may take several days.
- Many people with viral pneumonia recover without antibiotics, but some develop secondary bacterial pneumonia that then requires them.
- Your doctor may start antibiotics before test results come back if they suspect bacterial pneumonia, because waiting can be risky.
How bacterial and viral pneumonia develop differently
Bacterial pneumonia usually comes on suddenly. You may feel fine one day and very sick the next, with high fever, chills, and a cough that brings up thick, discolored mucus (often yellow, green, or rust-colored). Common bacteria that cause pneumonia include Streptococcus pneumoniae, Haemophilus influenzae, and Legionella. Bacterial pneumonia can follow a cold or flu, or it can strike on its own, especially in people with weakened immune systems or chronic lung disease.
Viral pneumonia typically develops more gradually. You might have a cough, sore throat, and body aches for several days before the pneumonia sets in. The cough is usually dry at first, and any mucus you bring up tends to be clear or whitish. Common viruses include influenza (flu), respiratory syncytial virus (RSV), and rhinovirus. Viral pneumonia is often milder than bacterial pneumonia, but it can still be serious, especially in older adults or people with heart or lung disease.
The distinction matters because bacterial pneumonia can worsen rapidly if left untreated, while viral pneumonia usually improves on its own over one to three weeks—though the cough can linger for weeks after that.
Tests your doctor uses to identify the cause
A chest X-ray is usually the first test. It shows whether pneumonia is present and sometimes hints at the cause: bacterial pneumonia often shows up as a dense, localized patch (called consolidation), while viral pneumonia may look more scattered or patchy. However, the X-ray alone cannot definitively say which type you have, so your doctor will use other clues.
Blood tests can help. A complete blood count (CBC) shows how many white blood cells you have; bacterial infections often trigger a higher count. Blood cultures—where a sample is grown in a lab to see if bacteria grow—can identify the specific bacterium, but results take 24 to 48 hours or longer. A procalcitonin test measures a protein your body makes in response to bacterial infection; high levels suggest bacteria rather than a virus.
Sputum culture is a test where you cough up mucus into a cup, and the lab grows any bacteria present to identify them. This takes several days but gives your doctor the exact organism and which antibiotics will work against it. Not all patients can produce a sputum sample easily, so this test is not always done.
Rapid viral tests can detect certain viruses (like flu or RSV) within hours, which helps your doctor rule out bacteria. These tests are most useful early in illness, when the virus is still shedding in high amounts.
Why doctors sometimes start antibiotics before knowing the cause
Bacterial pneumonia can become life-threatening quickly, so your doctor may start you on antibiotics right away if they suspect bacteria, even before test results come back. This is called empiric treatment—treating based on what is most likely rather than waiting for proof. The risk of delaying antibiotics in bacterial pneumonia (sepsis, organ failure, death) is considered greater than the risk of giving antibiotics unnecessarily if it turns out to be viral.
If tests later show your pneumonia is viral, your doctor will usually stop the antibiotics. Taking antibiotics when you do not need them carries its own risks: they can cause side effects, kill helpful bacteria in your gut, and contribute to antibiotic resistance—a growing problem where bacteria evolve to survive antibiotics.
Your doctor will discuss this reasoning with you. If you are concerned about taking antibiotics unnecessarily, ask what signs or test results would lead them to stop them if the cause turns out to be viral.
What happens if viral pneumonia turns into bacterial pneumonia
Sometimes a person starts with viral pneumonia, begins to recover, and then gets worse again. This is called secondary bacterial pneumonia, and it happens because the virus has damaged the lungs' defenses, making it easier for bacteria to take hold. When this occurs, antibiotics become necessary.
Signs that your viral pneumonia may have become bacterial include a sudden spike in fever after you were improving, a change in the color or character of your cough, increased shortness of breath, or new chest pain. If you notice these changes, contact your doctor right away. They may order new tests or start antibiotics.
Recovery and what to expect at home
If your pneumonia is viral, your main job is to rest, stay hydrated, and let your immune system do the work. Over-the-counter fever reducers and cough medicines can help you feel better, though some doctors recommend not suppressing the cough too much, since coughing helps clear mucus from your lungs. Most people with uncomplicated viral pneumonia feel better within a week or two, though fatigue and a lingering cough are common for several weeks.
If your pneumonia is bacterial and you are prescribed antibiotics, take the full course even if you feel better after a few days. Stopping early can allow bacteria to survive and regrow, sometimes in antibiotic-resistant forms. Most people on antibiotics for bacterial pneumonia start feeling better within 48 to 72 hours.
In either case, if you have trouble breathing, chest pain, confusion, or a very high fever, seek medical attention right away. These can be signs of serious pneumonia or complications.
Frequently Asked Questions
Can you have both bacterial and viral pneumonia at the same time?
Yes. Sometimes a viral infection damages the lungs enough that bacteria move in alongside the virus. This is called co-infection. Your doctor may treat both with antivirals (if available for that virus) and antibiotics. Blood and sputum tests help identify what organisms are present.
Does the color of mucus tell you if pneumonia is bacterial or viral?
Not reliably. Yellow, green, or rust-colored mucus is often associated with bacterial infection, but viral pneumonia can also produce discolored mucus. The color depends partly on how long the mucus has been sitting in your lungs and what your immune system is doing, not just the cause. Your doctor needs tests, not just what you cough up.
If I have viral pneumonia, do I need to go to the hospital?
Most people with viral pneumonia recover at home, but hospitalization may be needed if you have severe shortness of breath, very low oxygen levels, confusion, or other serious symptoms. Age, other health conditions, and how sick you are determine this. Your doctor will assess whether home care is safe for you.
How long does it take to get test results that show the cause?
Blood cultures and sputum cultures take 24 to 48 hours or longer. Rapid viral tests give results within hours. A chest X-ray is usually available within hours. Your doctor may start treatment before all results are back, especially if bacterial pneumonia is suspected, because waiting can be risky.
Can you catch pneumonia from someone else if it is viral?
Yes, viral pneumonia is contagious. The virus spreads through respiratory droplets when an infected person coughs or sneezes. Bacterial pneumonia is generally not contagious from person to person in the same way, though the bacteria can spread in certain settings like hospitals. Wash your hands often and cover your cough to reduce spread.