Light-night snacking isn’t just something college students dabble in. It’s a guilt-laden habit that haunts people of all ages, particularly those who struggle with their weight.

So what might contribute to the urge for cookies and chips after dinner? A new study suggests it could be sleep deprivation. Even when study participants were allowed to catch up on sleep over the weekend, the cravings persisted.

For the paper, published in February in the journal Current Biology, researchers used a deliciously rigorous study design to tease out the health effects of not sleeping enough and whether sleeping too little during the week could be offset by a lazy weekend lie-in. (Hat tip to Dr. Perry Wilson at Medscape, who first brought it to our attention.)

They took 36 healthy volunteers and confined them to a lab for two weeks. First, they had everyone sleep for nine hours per night for three nights. Then they randomly assigned the study participants to one of three groups: a “sleep restriction” group that was allowed to sleep just five hours per night; a control group that had the opportunity to sleep a luxurious nine hours per night; and a “sleep recovery” group that got only five hours per night for five nights, followed by a weekend sleep-in, and two more nights of sleep restriction.

The researchers gathered data on how much each participant slept and ate, as well as tracking their insulin sensitivity — or how much of the hormone the body needed to secrete in order to manage blood sugar levels. (Low insulin sensitivity, and insulin resistance, is a harbinger of Type 2 diabetes.) They also tracked the participants’ levels of melatonin, another hormone that indicates the body clock’s biological day and night.

What they found was an indictment of sleep deprivation — even after weekend catch-up sleep — and a potential explanation for why some diets fail. While all three groups ate about the same amount of calories, both of the sleep-deprived groups got more of their calories late in the day, in particular from snacking after dinner. They also gained more weight during the study period compared to the control group. So something about too little sleep spurred a heavier calorie intake later at night, and that difference showed up on the scale.

Even more alarming, the underslept groups experienced a decrease in their insulin sensitivity — an effect the control group didn’t see — meaning their patterns of eating and sleeping upset their metabolism in ways that could prime them for Type 2 diabetes. And again, weekend recovery sleep failed to protect people from decreased insulin sensitivity.

It’s only a short-term study, but a well-designed one — and it’s important because it adds to a growing body of evidence that chronic sleep deprivation is a risk factor for both obesity and diabetes. The study is also a reminder that sleep is often missing from the discussion of weight gain and obesity — and it shouldn’t be. To avoid tiredness-induced food cravings, we need to sleep well, consistently, every night.

So what is it about not sleeping enough that encourages snacking and weight gain?

There are a few potential explanations for why sleep-deprived folks gain weight more easily. One has to do with the metabolism. Before we get into the details, a quick recap on the three main ways our bodies metabolize energy. We’ve got the “basal metabolic rate” — or how you expend energy when you’re resting. There’s energy expenditure from physical activity. And there’s “diet-induced thermogenesis,” the amount of energy your body uses in order to digest and absorb calories in food. That last one accounts for about 10 percent of the body’s overall energy expenditure.

Researchers have looked at whether people expend more energy processing a meal later in the day versus earlier and found that, independent of physical activity, the body uses less energy to digest food late in the day. So that means we may convert more calories to fat, instead of burning them off, when we eat late at night.

Researchers have also repeatedly found that when we’re tired — surprise, surprise — we eat more. In a meta-analysis of 11 studies, the authors showed that people ate 385 extra calories following a night of sleep deprivation. That’s about the same amount as a serving of Häagen-Dazs peanut butter ice cream a day.

There’s a hormone hypothesis to explain this tendency: A lack of sleep hampers our hunger hormones leptin and ghrelin, potentially contributing to an increase in appetite. Sleep loss may also change how our brains perceive food, Vox’s Brian Resnick has explained. A lack of sleep seems to alter our food-reward system, causing us to get more excited by a cupcake or french fries than we would if we were well rested.

Besides weight gain, another important finding is that late-night eating is associated with a higher risk of diabetes. Researchers have shown that the body has a harder time managing glucose at night. And the reason is that the circadian system — the body’s internal clock, which is running in every single cell — seems to regulate how the body manages calories at different times of the day.

”What we have found is that if you eat an identical meal in the morning or evening, the glucose response is relatively impaired in the evening compared to the morning,” Dr. Frank Scheer, a neuroscientist at Brigham and Women’s Hospital and an associate professor at Harvard Medical School, told Vox previously. “In the evening hours, we can’t cope with the glucose load as well.”

So not only do we do worse at managing calories when we’re fatigued, and may more often eat late at night, but we tend to eat more calories too.

Too many Americans are sleep-deprived

While the official recommendation from the American Academy of Sleep Medicine is at least seven hours per night for adults, a third of Americans report sleeping less than that, on average.

So how can we get more sleep? First, get your basic sleep hygiene in check: Avoid caffeine after lunch, exercise regularly but not too late in the day, and avoid alcohol and heavy meals before bed.

And, for the love of God, get screens out of your bedroom. “If you can maintain sleep stability, that means you are seeing that same light at the same time every day and your body will pick up on that,” the author of Sleepyhead: The Neuroscience of a Good Night’s Rest, Henry Nicholls, told Vox’s Sean Illing. “And yeah, most people do not appreciate how disruptive artificial light is to the brain. It confuses your brain into thinking it’s daytime when it’s actually bedtime.” Now we know that’s the last thing we want to do if we’re trying to lose weight.