Going for a run can give your brain an immediate boost, helping you feel calmer, happier, and more focused. But new research shows that exercise's positive impact on the brain is long-lasting.

A study published online in Neurology, the medical journal of the American Academy of Neurology, found that poor cardiovascular fitness in middle age is associated with having a smaller brain 20 years later.

Brain shrinkage is a natural function of aging, but those in the study who performed poorly on a test of cardiovascular fitness, as well as those whose blood pressure and heart rate went up at a higher rate during exercise, were more likely to have smaller brains 20 years later, which is associated with cognitive decline and an increased risk for dementia.

“The broad message is that health and lifestyle choices you make throughout your life may have consequences many years later,” study author Nicole Spartano, Ph.D., of the Boston University School of Medicine, wrote in an email to Runner’s World. “We found that poor fitness in midlife was linked to more rapid brain aging two decades later. This message may be especially important for people with heart disease or at risk for heart disease, in which we found an even stronger relationship between fitness and brain aging.”

Between 1979 and 1983, more than 1,500 participants in the Framingham Offspring Study, with a mean age of 40, performed a treadmill test to exhaustion or 85 percent of their estimated maximum heart rate. (The test began at 1.7 miles per hour, and gradually progressed to 5 miles per hour and an 18 percent grade for those who made it that far.) Roughly 20 years later, between 1998 and 2001, they were retested (with a modified protocol) and given MRI brain scans.

The study’s participants had an estimated average VO2 max of 39 mL/kg/min. For every one standard deviation lower a person performed on the initial treadmill test, they were found to have a lower brain volume 20 years later, equivalent to two years of accelerated brain aging. When researchers excluded participants who developed heart disease or took beta blockers to control blood pressure or heart problems, one standard deviation lower exercise capacity was equivalent to one year of accelerated brain aging.

Spartano wrote that other studies have indicated that the brains of those who maintain a cardiovascular exercise program may shrink more slowly because of increased blood flow and oxygen delivered to the brain.

“Over the course of a lifetime, improved blood flow may have an impact on brain aging and prevent cognitive decline in older age.”