Sleep – a lot like eating food – is one of those things we need to live, but seemingly there are plenty of ways to do it wrong.

A new study has weighed into the debate. Looking at UK Biobank data from almost 500,000 adults, researchers conclude that seven hours of sleep per night is the optimal amount for good mental health, wellbeing and cognitive performance, for people in their late 30s to early 70s.

"We identified a nonlinear association between sleep, with approximately seven hours as the optimal sleep duration, and genetic and cognitive factors, brain structure, and mental health as key measures," the researchers write in their new paper.

"Longitudinal analysis revealed that both insufficient and excessive sleep duration were significantly associated with a decline in cognition on follow up."

The team, led by neuroscientist Yuzhu Li from Fudan University in China and psychiatry researcher Barbara Sahakian from Cambridge University, looked at data from 498,277 participants aged 38-73 years as part of the UK Biobank study.

Around 48,500 of the participants also underwent neuroimaging, and almost 157,000 participants completed an online mental health questionnaire follow-up. All these data points went together to provide a pretty comprehensive view of how the amount of sleep people get correlates to other aspects of their mental and brain health.

Like other studies of this nature, the researchers found a U-shape in the data. Too little sleep lowered all measures of cognitive function and mental health that the team looked at. But so did too much sleep – up to 12-13 hours a day in some cases.

Because of the neuroimaging data, the researchers were also able to look into whether there were brain structural or genetic mechanisms behind the U-shape curve. Modeling by the researchers suggests that genetics and brain structure do play a role, but much more research will be needed to follow up on these leads.

"While we can't say conclusively that too little or too much sleep causes cognitive problems, our analysis looking at individuals over a longer period of time appears to support this idea," says one of the researchers, Jianfeng Feng from Fudan University.

"But the reasons why older people have poorer sleep appear to be complex, influenced by a combination of our genetic makeup and the structure of our brains."

So, with all that in mind, we need to mention a couple of caveats. This research is very expansive, but it's still just an observational study, which only demonstrates associations seen in the data.

Unfortunately, we can't tell if sleeping less or more than seven hours actually causes issues in mental health, wellbeing, or cognitive performance, or conversely whether those problems are what lead people to sleep more or less.

Secondly, this study is not saying that sleeping six or eight hours is going to cause significant changes to your individual wellbeing. There are lots of reasons why people can't sleep seven hours every night – whether that's stress, work, or just needing to get up in the middle of the night to pee.

As you can see in the figure below, the changes are much more apparent on the far ends of the scale, such as one hour or 13 hours of sleep a night. Seven is just the optimal number in the middle of the curve.

(Li et al., Nature Aging, 2022)

Above: Graphs showing significant nonlinear association between sleep duration and cognitive function and mental health.

More importantly, if you don't feel refreshed unless you get eight hours of sleep a night, don't try to wake up an hour earlier and expect health benefits.

This study is helpful in showing that getting seven hours of sleep a night as we head into middle and older age is a worthy goal. But we shouldn't beat ourselves up if we can't get that amount as individuals.

"Getting a good night's sleep is important at all stages of life, but particularly as we age," says Sahakian.

"Finding ways to improve sleep for older people could be crucial to helping them maintain good mental health and wellbeing and avoiding cognitive decline, particularly for patients with psychiatric disorders and dementias."

And if you are struggling to get enough sleep, naps can also really help.

The research has been published in Nature Aging.