Not being able to sleep is bad at the best of times, but it also makes us fat.

We’ve long known there is a link between poor sleep and a number of health problems, including obesity, but we’ve not always understood why.

A study published in the journal sleep suggests that a bad night’s sleep changes our brain chemistry, making us crave energy dense food like sweets, cookies and chips.

The researchers from the University of Chicago say, a lack of sleep sparks chemical changes similar to those of cannabis to bring a kind of “marijuana munchies” state.

“We know that marijuana activates the endocannabinoid system and causes people to overeat when they are not hungry, and they normally eat yummy sweet and fatty foods,” lead researcher Eric Hanlon told the Guardian. “Sleep restriction may cause overeating by acting in the same manner.”

To come to this conclusion, Hanlon and his team, took 14 healthy, non-obese men and women and split them into two groups.

Over four days, the groups’ sleep and food were carefully monitored and controlled.

They were given meals at 9am, 2pm and 7pm but one group slept for 7.5 hours while the other were woken after just four hours. They then swapped the groups sleeping hours. On the final night of each rotation, participants were allowed to eat whatever they wanted.

When the group was sleep deprived, they ate on average 1200kj more – about the equivalent of another small main meal.

The researchers also measured participants satiety hormone leptin, hunger hormone ghrelin, and endocannabinoids (which control of feeding, appetite, and energy balance).

They found that the sleep-deprived group’s endocannabinoids, in particular one type that heightens the pleasure from eating sweet or salty foods, were elevated and stayed elevated into the evening. The early-afternoon drive for hedonic eating may be stronger and last longer in a state of sleep debt.

Although the study is small and the researchers acknowledge more research is required, they say it provides an “increased understanding of the mechanisms linking insufficient sleep and the risk of weight gain [which] is important to design preventive strategies.”

Eating poor food before bed is also likely to lead to a bad night’s sleep, causing a compounding effect. High fibre and whole grain foods are the most likely to give you a good night’s sleep.