Most of us are well aware of the benefits of physical activity. Daily runs, a couple of days of lifting weights, and eating healthy can reduce our risk of obesity, one of the most common causes of type 2 diabetes, heart disease, and some cancers. The thing with all these diseases is that they often cascade into a slew of other health problems. And a new study finds that one of those problems is cognitive decline.

Previous studies have linked diabetes to a drop in brain function. One from last year, for example, found that people with uncontrolled blood glucose (sugar) levels were 40 percent more likely to develop dementia. That wasn’t even with a diabetes diagnosis. Another one found that people who experienced hypoglycemia were two times more likely to develop dementia. The new study, from the Johns Hopkins Bloomberg School of Public Health, now finds that this cognitive decline can occur at a rate five years faster than it would normally. In other words, a 60-year-old with diabetes has about the same cognitive decline as a person aged 65.

For the study, the researchers looked at data from the Atherosclerosis Risk in Communities Study, which followed 15,792 middle-aged adults beginning in 1987 and followed them for about 11 years. During that time, participants followed up every three years, four different times. They then came back once more between 2011 and 2013. When the researchers compared their cognitive function during visits two, four, and five, they found those who had poorly controlled diabetes were 19 percent more likely to have lost brain function too. These results held to a lesser extent among those with pre-diabetes and controlled diabetes.

“The lesson is that to have a healthy brain when you’re 70, you need to eat right and exercise when you’re 50,” said study leader Dr. Elizabeth Selvin, an associate professor of epidemiology at School of Public Health, in a press release. “There is a substantial cognitive decline associated with diabetes… and we know how to prevent or delay the diabetes associated with this decline.”

That prevention, of course, involves maintaining a healthy weight through physical activity and a healthy diet. Losing just five to 10 pounds of weight can dramatically reduce a person’s risk of developing diabetes, Selvin said. Thus, the risk of dementia also goes down. How this works is unclear, but it’s probably because doing so will lower blood pressure — diabetics are three times more likely to have hypertension — thus reducing pressure in the brain’s blood vessels.

“There are many ways we can reduce the impact of blood vessel disease — by prevention or control of diabetes and hypertension, reduction in smoking, increase in exercise and improvements in diet,” said co-author Dr. A. Richey Sharrett, adjunct professor at the School of Public Health, in the release. “Knowing that the risk for cognitive impairments begins with diabetes and other risk factors in mid-life can be a strong motivator for patients and their doctors to adopt and maintain long-term healthy practices.”

Source: Schneider A, Coresh J, Selvin E, et al. Diabetes in midlife and cognitive change over 20 years: the Atherosclerosis Risk in Communities Neurocognitive Study. Annals of Internal Medicine. 2014.