Researchers at the University of Warwick found that there is an association between both quality and duration of sleep and brain function which changes with age.
Researchers analysed sleep and cognitive (brain function) data from 3,968 men and 4,821 women who took part in the English Longitudinal Study of Ageing (ELSA).
Respondents reported on the quality and quantity of sleep over the period of a month.
In adults aged between 50 and 64 years of age, short sleep (less than 6 hours per night) and long sleep (more than 8 hours per night) were associated with lower brain function scores.
By contrast, in older adults (65-89 years) lower brain function scores were only observed in long sleepers.
Researcher Dr Michelle A Miller said "6-8 hours of sleep per night is particularly important for optimum brain function, in younger adults".
"These results are consistent with our previous research, which showed that 6-8 hours of sleep per night was optimal for physical health, including lowest risk of developing obesity, hypertension, diabetes, heart disease and stroke," Miller said.
In the younger pre-retirement aged adults, sleep quality did not have any significant association with brain function scores, whereas in the older adults (more than 65 years), there was a significant relationship between sleep quality and the observed scores.
"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," said Professor Francesco Cappuccio.
The research was published in the journal PLOS ONE.