A lack of rest overnight as you get older can have a dramatic impact on your memory and ability to carry out everyday tasks.
Researchers at Warwick University found sleeping for a full eight hours a night can have a marked effect on brain function.
Professor Francesco Cappuccio, of the university's medical school, said: "Sleep is important for good health and mental wellbeing.
"Optimising sleep at an older age may help to delay the decline in brain function seen with age, or indeed may slow or prevent the rapid decline that leads to dementia."
The team analysed data from 3,968 men and 4,821 women. In adults aged between 50 and 64, short sleep duration of six hours a night or under was associated with lower brain function scores.
Sleeping too long could also impair brain function, the team found. Older adults aged 65-89 who had lower scores were found to be long sleepers who got more than eight hours a night.
The research, published in the journal PLOS ONE, showed that in pre-retirement age adults sleep quality did not have any significant association with brain function scores.