If you’ve never craved a late-night snack of carrots or apples, you’re not alone. It’s a normal biological response to reach for junk food when you’re sleepy.

You may already know that getting a good night’s sleep is essential for your metabolism to function normally, but did you know sleep, or lack thereof, can also dictate what types of food you may crave?

Here’s the science behind it.

There are two hormones that control our urges to eat: leptin, which suppresses appetite, and ghrelin which increases our hunger.

Research published in the medical journal Psychoneuroendocrinology shows that sleep deprivation affects the balance of these two hormones, mainly spiking the one that makes you hungry.

So why are you reaching for junk food instead of kale? That’s thanks to the endocannabinoid system.

They bind to the same receptors as the active ingredient in marijuana, which can trigger the “munchies.” And that system makes us crave fatty, starchy and sugary foods.

According to a 2016 study, just like ghrelin, when we don’t get enough sleep, that system goes into overdrive.

Experts are still unclear why this all happens, but if you want to limit those late-night cookie cravings, it might help to get more rest.