We’ve all heard the advice to close down the kitchen after a certain time, which makes sense: nighttime snacking can quickly get out of hand, and has the potential to seriously derail our weight-loss goals. So why is it so irresistible? Turns out, it’s not just a matter of boredom or weakened motivation. Your body might actually be pushing you towards the pantry or fridge.

A recent study published in the International Journal of Obesity found that participants who felt stressed saw their levels of the hunger hormone ghrelin rise in the evening. At the same time, their bodies produced less peptide YY, a hormone that contributes to feelings of fullness. So if you’re like many who often find themselves feeling overwhelmed and exhausted after a long day, your hormones may be to blame for overeating.

This kind of hormonal shift might have been beneficial back in our hunter-gatherer days. “During the daylight, it would have made more sense to prioritize going out to hunt or forage for food. When it was dark, it made more sense to stay close to home and eat,” says lead study author Susan Carnell, PhD, an assistant professor of psychiatry and behavioral sciences at Johns Hopkins University School of Medicine. At the same time, feeling stressed probably meant that your survival was threatened. “So it makes sense to load up on calories while you can, to tide you over if your food source should suddenly disappear,” Carnell adds.

Get the better newsletter. This site is protected by recaptcha

None of this is so useful today, of course. Having ready access to a kitchen stocked with food means it’s easy to scarf down hundreds of calories that we really don’t need. And the threat of a looming work deadline or childcare conflict (the babysitter cancelled again!) doesn’t exactly justify gorging on a pint of chocolate ice cream.

It’s hard to find other behaviors that are as rewarding as food. You could say you’re going to take a nice bath, but the payoff isn’t as intense or immediate.

Not to mention that eating a salty, sugary or fatty snack activates the brain’s pleasure center in a big way. “It’s hard to find other behaviors that are as rewarding as food,” says Kelly Allison, PhD, Director of the Center for Weight and Eating Disorders at the University of Pennsylvania Perelman School of Medicine. “You could say you’re going to take a nice bath, but the payoff isn’t as intense or immediate.” Drawing the bath takes work — even just a few minutes’ worth — but reaching into a bag of chips is practically effortless.

The urge to snack at night may be even stronger for people who work hard to stick to healthier habits earlier in the day. “In part, people eat at night because of decision fatigue,” explains mindful eating expert Susan Albers, PsyD. Come nighttime, you’re worn out by the hundreds of choices you’ve had to make since waking up and your decision-making skills weaken. Rather than consciously opting for the carrots, you rely on autopilot or impulse and go with the cupcake, Albers says.

It might be reassuring to think that our inability to say no to the popcorn bowl or cookie jar isn’t just a lack of willpower. Still, there are effective ways to keep the unhealthy habit in check. “It’s hard to overcome your biology,” Carnell says. “Rather than just relying on willpower or feeling guilty, there might be some structural changes you can make.” In other words? If you can’t control your brain, try to control the cues that feed it. A few easy ways to do that:

Don’t restrict yourself during the day. Avoid skipping meals or snacks because you’re busy — or because you want to try to “save up” your calories for later. “Depriving yourself often directly leads to overeating at night when you’re tired from a long day,” Albers says.

Avoid skipping meals or snacks because you’re busy — or because you want to try to “save up” your calories for later. “Depriving yourself often directly leads to overeating at night when you’re tired from a long day,” Albers says. Form a new nighttime habit. Used to having a bag of pretzels whenever you watch TV? Try a different evening activity that you don’t associate with food like reading a book, taking a walk or listening to music, Albers says.

Used to having a bag of pretzels whenever you watch TV? Try a different evening activity that you don’t associate with food like reading a book, taking a walk or listening to music, Albers says. Portion out your snacks. You don’t have to swear off nighttime snacks completely, but it's important to be mindful of your portions so you don’t end up overdoing it. Instead of munching directly from the box or bag, measure out a serving and eat it from a bowl or plate, Allison recommends. Instead of raiding the candy drawer, stick to a snack that has between 150 and 250 calories, and offers up a mix of good carbs, healthy fats and protein, says Jackie Newgent, RDN, culinary nutritionist and author of The All-Natural Diabetes Cookbook. This will help fill you up and prevent you from going back into the kitchen for more.

You don’t have to swear off nighttime snacks completely, but it's important to be mindful of your portions so you don’t end up overdoing it. Instead of munching directly from the box or bag, measure out a serving and eat it from a bowl or plate, Allison recommends. Instead of raiding the candy drawer, stick to a snack that has between 150 and 250 calories, and offers up a mix of good carbs, healthy fats and protein, says Jackie Newgent, RDN, culinary nutritionist and author of The All-Natural Diabetes Cookbook. This will help fill you up and prevent you from going back into the kitchen for more. Keep tabs on how much TV you watch . For most of us, the screen is a powerful cue for nighttime snacking. Research shows that more time in front of the television often means more unhealthy eating. So if you still want to tune in, set a limit on the number of episodes (think: one or two, tops), Albers says, and be careful of mindlessly munching while you zone out in front of the tube.

. For most of us, the screen is a powerful cue for nighttime snacking. Research shows that more time in front of the television often means more unhealthy eating. So if you still want to tune in, set a limit on the number of episodes (think: one or two, tops), Albers says, and be careful of mindlessly munching while you zone out in front of the tube. Set a closing time for the kitchen. Shut the lights off and move your activities elsewhere. You can even put a “CLOSED” sign on the fridge, if it helps. It may feel a little silly, “but it can be a reminder when you don’t have the capacity to really think about those decisions,” Allison says.

WHAT A NUTRITIONIST WANTS YOU TO KNOW

Want more tips like these? NBC News BETTER is obsessed with finding easier, healthier and smarter ways to live. Sign up for our newsletter and follow us on Facebook, Twitter and Instagram.