A study by public health scientists has revealed that getting too much or too little sleep can prematurely age your brain by up to seven years.
They found that middle-aged adults whose sleep decreased to less than six hours a night over a five-year period suffered lower scores in reasoning and vocabulary tests.
Those whose nightly sleep increased to more than eight hours also showed signs of accelerated cognitive decline.
But they found that women who had maintained seven hours of sleep per night performed best in cognitive tests as did men who slept between six and eight hours.
The findings suggest that regularly sleeping for seven hours during the night can help to reduce the cognitive decline that occurs as we grow older.
The researchers have now called for better public health advice about the importance of getting the right amount of sleep.
Dr Jane Ferrie, who led the research in the department of epidemiology and public health at University College London, said the decline in brain function suffered by people who got too much or too little sleep was equivalent to them having aged between four and seven years.
She said: "Sleep duration generally decreases with age and so does cognitive function, so we wanted to see if there was a relationship with that change in sleep.
"It was surprising that when people have longer durations of sleep, they had a lower cognitive function scores in all of the tests apart from memory.
"We think this could be to do with fragmentation of sleep which means although people are in bed for a long time, they are not necessarily having enough quality sleep.
"We calculated these changes in sleep are producing a cognitive deficit that is equivalent to a person having aged by between four and seven years."
The researchers used data from a long term public health survey known as the Whitehall II study.
Using data from questionnaires and cognitive tests completed by 5,431 participants, Dr Ferrie and her colleagues were able to assess how changes in sleep duration over a five-year period related to changes in cognitive scores.
The participants, who were aged between 35 and 55 years old, were asked to carry out six cognitive tests that examined reasoning, vocabulary, fluency and memory.
The researchers found that 25 per cent of the women and 18 per cent of the men taking part had decreased the amount of sleep they got each night while 7.4 per cent of the women and 8.6 per cent of the men had increased the amount of sleep they got.
The results showed that those whose sleep duration had fallen to less than six hours a night over the five hour period were had lower test scores for reasoning and vocabulary.
Those whose sleep had increased to more than eight hours scored lower in all the tests apart from memory.
Dr Ferrie said more work was needed to understand exactly how changes in sleep patterns influence cognitive function in adults and if other conditions such as depression, which can also affect sleep and cognitive function, were playing a role.
But she called for public health authorities to take sleep more seriously when issuing advice.
She said: "There are incredible pressures on people to live 24/7 lives, yet sleep has had very little attention when compared to other health related behaviours such as alcohol consumption and smoking.
"I would like to see sleep being taken more seriously as a subject for health promotion."
Dr John Shneerson, president of the British Sleep Society, said: "Sleep can be looked at very much like food - if you get too little it can be bad for you and if you get too much it can also be harmful.
"Sleep is beneficial both on a cellular level to allow the cells in the brain to get rid of waste materials and build up their energy stores, but it is also important for consolidating memories."