Coffee often gets a bad rap, perhaps due to the notion that anything so enjoyable must be bad for you. But in fact, studies show that coffee has numerous health benefits.

Coffee’s effect on the liver has the largest body of evidence. Studies have found that coffee may reduce the risk of liver fibrosis and cirrhosis, fatty liver disease, alcohol-related liver disease and liver cancer. An analysis comparing countries with and without heavy coffee consumption suggests that drinking two cups a day could reduce the number of liver-related deaths by more than 450,000 a year worldwide. Another study found that drinking three cups a day cut the risk of death in half for people with both HIV and hepatitis C.

Coffee may also have benefits related to other types of cancer. Studies have found that coffee may lower the risk of prostate cancer, improve survival for people with metastatic colon cancer and reduce the risk of death after breast cancer treatment. Various meta-analyses of pooled studies have found that drinking coffee either slightly lowered or had no effect on cancer risk overall.

What’s more, research suggests that coffee may protect against type 2 diabetes, strokes, dementia and depression. Experts think the beneficial effects of coffee—both caffeinated and decaf—may be due to its anti-inflammatory effects and the presence of healthful plant alkaloids. If coffee is not to your liking, tea has many of the same benefits.

But that doesn’t mean coffee consumption is for everyone. Too much coffee can make some people feel jittery or anxious, interfere with sleep and worsen acid reflux. Susceptible people may experience a racing heart or a spike in blood pressure. Some people can become dependent on caffeine and feel irritable or drowsy when they don’t get their cup of joe. Plus, drinking coffee with cream and sugar adds calories.

According to the Food and Drug Administration, most adults can safely consume 400 milligrams of caffeine a day, the amount in about four or five cups of brewed coffee. The American College of Obstetricians and Gynecologists recommends no more than 200 milligrams a day for pregnant women. But the best advice is to drink as much—or as little—coffee as feels right for you.