It’s harder to resist snacking when you’re tired, in fact, a lack of sleep can give you the munchies. That's because sleep loss increases levels of the same brain chemicals marijuana does, according to a new study.

Inadequate sleep has been known to lead to poor food choices, overeating and weight gain, but the reasons have not been understood until now.

Sleep deprivation increases the levels of a chemical signal in the blood which makes sweet, salty and fatty foods particularly appealing. Levels of this chemical, called endocannabinoid 2-arachidonoylglycerol (2-AG), are usually low overnight, and gradually rise during the day, peaking in early afternoon.

The sleep-deprived people in the study consumed more than 300 extra calories, and their fat intake was twice what it would have been if they gotten a full night’s sleep.

The hunger and eating habits of young volunteers were tracked for four days when they slept about 7.5 hours a night and for four days when they only got about 4.2 hours of sleep. Everyone in the study ate the same meals three times a day. In addition to testing the participants’ levels of the hormones ghrelin, which increases appetite, and leptin, which signals we are full, the researchers also measured their levels of 2-AG.

Levels of 2-AG increased and stayed high through the evening hours In the sleep-deprived group,. Even after eating a meal that provided 90 percent of their daily calorie needs, they couldn’t resist eating candy, chips and cookies two hours later. The sleep-deprived people in the study consumed more than 300 extra calories, and their fat intake was twice what it would have been if they gotten a full night’s sleep.

Participants’ cravings for junk food were strongest in the late afternoon and early evening, the times of the day when snacking brings on the most weight gain. It may seem like you'd burn lots more calories by being awake longer, but sleeping less only means you need about 17 more calories per hour, hardly enough to make up for the added calories of a late afternoon binge.

According to the Centers for Disease Control and Prevention, approximately one-third of Americans sleep less than seven hours a night, and more than one-third of US adults are obese. In 2013, a Gallup poll found that US adults sleep only about 6.8 hours per night, and 40 percent sleep six hours or less.

Erin Hanlon, PhD, of the University of Chicago School of Medicine, said in a statement, “…if you have a [candy bar], and you’ve had enough sleep, you can control your natural response. But if you’re sleep-deprived, your hedonic drive for certain foods gets stronger, and your ability to resist them may be impaired. So you are more likely to eat it. Do that again and again, and you pack on the pounds.”

Sleep has to be one of the easier ways to lose weight — or at least help keep it under control. Add getting enough sleep to your weight loss toolbox.

The study is published in the journal Sleep.