The research led by University of Exeter in the UK used data from more than 2,000 mentally fit people over the age of 65.
Researchers examined the theory that experiences in early or mid life which challenge the brain make people more resilient to changes resulting from age or illness - they have higher "cognitive reserve".
The analysis found that people with higher levels of reserve are more likely to stay mentally fit for longer, making the brain more resilient to illnesses such as dementia.
"It is important that we understand how and why this occurs, so we can give people meaningful and effective measures to take control of living full and active lives into older age.
More From This Section
"People who engage in stimulating activity which stretches the brain, challenging it to use different strategies that exercise a variety of networks, have higher 'Cognitive reserve'," said Clare.
The research team analysed whether a healthy lifestyle was associated with better performance on a mental ability test.
They found that a healthy diet, more physical activity, more social and mentally stimulating activity and moderate alcohol consumption all seemed to boost cognitive performance.
"We found that people with a healthier lifestyle had better scores on tests of mental ability, and this was partly accounted for by their level of cognitive reserve," said Professor Bob Woods of Bangor University in the UK.
The study was published in the journal PLOS Medicine.