According to a new study, both too little and too much sleep could have a negative effect on the brain.

According to the preliminary results from the one of the world’s largest sleep studies, people who average between seven to eight hours of sleep per night perform better cognitively than those who sleep either less or more than that recommended amount.

The researchers from the University of Western Ontario found that both reasoning and verbal abilities were two of the skills most strongly impacted by sleeping habits.

 However, short-term memory performance remained relatively unaffected by sleep.

“We found the optimum amount of sleep to keep your brain performing its best is seven to eight hours every night,” Conor Wild, Owen Lab Research Associate and the study's lead author, said in a statement. “That corresponds to what the doctors will tell you need to keep your body in tip-top shape, as well.

“We also found that people that slept more than that amount were equally impaired as those who slept too little,” he added.

The researchers discovered that sleep affected all adults basically equally and the amount of sleep—seven to eight hours—associated with highly functional cognitive behavior was the same for everyone, regardless of age. They also found that the impairment associated with sleeping less or more than the recommended amount did not depend on the age of the person.

About half of the participants in the study self-reported that they slept less than 6.3 hours and those that reportedly slept less than four hours per night performed cognitively as if they were almost eight years older than actually they were.

Participants who slept more than usual the night before the study performed better than those who slept their usual amount or less.

Beginning in June of 2017, the study included more than 40,000 volunteers from around the world who answered an in-depth questionnaire and 10,000 participants that performed in a series of cognitive performance activities, which included various memory and reasoning tests.

“We really wanted to capture the sleeping habits of people around the entire globe,” Adrian Owen, a Professor at The Brain and Mind Institute and the former Canada Excellence Research Chair in Cognitive Neuroscience and Imaging, said in a statement. “Obviously, there have been many smaller sleep studies of people in laboratories but we wanted to find out what sleep is like in the real world.

“People who logged in gave us a lot of information about themselves,” he added. “We had a fairly extensive questionnaire and they told us things like which medications they were on, how old they were, where they were in the world and what kind of education they'd received because these are all factors that might have contributed to some of the results.”

The study was published in Sleep.