We all know that exercise is good for you — it keeps the heart healthy, works out the muscles and prepares you to take the stairs at work without fainting from exhaustion. But does all that activity actually prevent you from getting sick?

According to a study published online by the Archives of Internal Medicine, the answer is yes. Researchers say that people who are more fit when they are middle-aged have a lower rate of chronic diseases, including heart problems, diabetes, stroke, kidney disease, obstructive pulmonary conditions, lung cancer, colon cancer and Alzheimer’s disease.

Previous studies have shown that people who are more physically fit have a lower risk of dying early than those who aren’t as in shape, but the current analysis, led by Dr. Jarrett Berry of the University of Texas Southwestern Medical Center, is the first to expose a connection with chronic diseases. Berry and his colleagues compared data on fitness levels of 18,670 healthy men and women in their 40s and 50s to Medicare claims for chronic disease treatments a couple of decades later, when the participants became eligible for coverage after age 65. Each of the volunteers performed a treadmill test, during which the researchers measured the length of time they exercised to exhaustion as an indicator of their fitness. For every one-unit improvement in fitness, measured as metabolic equivalents, the volunteers enjoyed a 20% drop in the incidence of the eight conditions the scientists tracked.

Even more encouraging, says Berry, is the fact that those with the highest fitness levels battled fewer chronic conditions in the last five years of life, meaning they spent more of this time healthy rather than burdened by disease. “The results show that fitness can not only delay morbidity but prevent it,” says Berry.

So how do you get fit? It’s partly genetic, he says, but exercise can help. About half of a person’s fitness is determined by the cumulative effect of lifetime exercise, which is why physical activity during mid-life can have such long-lasting effects on health. So jogging, swimming, taking daily walks or being more physically active in general can pay off by making you healthier in your waning years.

Alice Park is a writer at TIME. Find her on Twitter at @aliceparkny. You can also continue the discussion on TIME’s Facebook page and on Twitter at @TIME.