Our brains decrease in size as we age, increasing our risk of dementia and cognitive decline. But getting regular exercise could be a fountain of youth for our long-term mental health, suggests new research published in the journal Neurology that links physical fitness in middle age with larger brain sizes later on in life, CNN reports.

For the study, researchers at Boston University School of Medicine recruited more than 1,500 middle-age adults without dementia or heart disease to take a treadmill test to determine their physical fitness. Specifically, scientists measured the length of time participants could exercise before their heart rate reached a certain level, as well as heart rate and blood pressure responses. Twenty years later, participants took the same test, along with a series of MRI scans.

The brain scans showed that participants who did not perform as well on their initial treadmill test had smaller brains two decades later than those who performed well. What’s more, the brains of subjects whose fitness was poor but who hadn’t developed heart problems and weren’t on blood pressure meds showed one year of accelerated brain aging in the follow-up study.  In addition, researchers found the brains of fitness participants who did develop cardiovascular disease and were on meds had experienced the equivalent of two years of accelerated aging.

“From other studies, we know that exercise training programs that improve fitness may increase blood flow and oxygen to the brain over the short term,” said Nicole Spartano, PhD, a postdoctoral fellow at Boston University School of Medicine and study author. “Over the course of a lifetime, improved blood flow may have an impact on brain aging and prevent cognitive decline in older age.”

The study also showed that for people with heart disease, fitness might be particularly important for the prevention of brain aging.  Click here for some key heart health tips.