Updated

You must have sweated off hundreds of calories during that Spin class, so it's totally okay to indulge in a bowl of ice cream when you get home—right? Not so fast.

Research shows that people tend to reward themselves with rich foods and large portions after exercising, and that they often eat back all of (if not more than) the calories they just burned. There's nothing wrong with small snack or a filling dinner after exercising, said Emily Brown, a wellness dietitian at the Mayo Clinic in Rochester, Minn. and former professional runner. But before you dig in, you have to understand your body's true nutrition needs so you don't end up gaining weight despite all your hard work. Read on for the smartest ways to refuel—and silence that rumbling belly.

Work out right before a meal
If you're always hungry after you exercise—regardless of whether you ate beforehand or how many calories you burned—try to schedule your workouts before one of your main meals, Brown said. That way, you can refuel with calories you would have consumed anyway, without having to add extra snacks into your day.

Health.com: Get a Flat Belly in 4 Weeks

This strategy can work regardless of whether you're a morning, noon, or nighttime exerciser. Have a small snack when you wake up and eat a larger breakfast after your a.m. run; hit the gym at lunchtime and pick up a sandwich on the way back to the office; or prep your dinner ahead of time so you can just heat it up when you get home from an evening barre class.

Make your workout fun
Thinking about exercise less as a chore and more as something you do because you enjoy it can help you eat less afterward, according to a 2014 Cornell University study. Researchers led volunteers on a 1.4—mile walk, telling half of them that it was for exercise and half that it was a scenic stroll. The "exercise" group ate 35 percent more chocolate pudding for dessert than the "scenic" group. In another experiment, volunteers were given post-walk snacks, and the "exercisers" ate 124 percent more calories than those who were told it was just for fun.

Related: 20 Ways to Make Exercise a Habit That Lasts

Pair protein and carbs
When you do need a snack to recover from a tough sweat session, Brown recommends a 4:1 ratio of carbohydrates to protein.

"This will allow you to begin to replenish your energy levels and repair muscle damage resulting from the workout," she said.

For workouts less than an hour, keep your snack to 150 to 200 calories total—an open-faced peanut butter and jelly sandwich, a slice of turkey and cheese on crackers, or a handful of trail mix, for example. If you worked out for longer than an hour and aren't eating a full meal soon, aim for half a gram of carbohydrates for every pound of body weight. A 140-pound person, for example, should refuel with 70 grams of carbs and about 18 grams of protein. (An energy bar or protein shake, plus one of the healthy snacks above, should fit the bill.)

Get milk
Low-fat dairy is another great recovery food with plenty of protein to help tide you over until your next meal, said Jim White, RD, owner of Jim White Fitness and Nutrition Studios in Virginia Beach. Plus, studies have shown that refueling with dairy—low-fat chocolate milk, specifically—helps improve subsequent athletic performances better than traditional sports drinks.

Stop eating out of habit
Sometimes, overeating after exercise is more a consequence of routine than anything else.

"When you consistently consume a 500-calorie smoothie after you finish up at the gym, you start to get into that habit of consuming a smoothie no matter how long or intense your exercise was," Brown said.

Her solution? Choose different snacks for different workouts—the shorter the duration, the fewer calories you need to replenish— and always pay attention to your hunger cues.

"It's important for weight loss and weight maintenance to get in tune with your body and learn to eat in response to hunger, versus eating in response to boredom, stress, or the idea of rewarding yourself for exercising,” she said.

Health.com: 14 Ways to Cut Portions Without Feeling Hungry

Don't trust your tracker
Activity trackers like the Fitbit and Jawbone have become a trendy way to estimate physical activity expenditure throughout the day. But a 2014 Iowa State University study found that not all devices are accurate in estimating calorie burn during workouts. The least accurate device, the Basis Band, had an error rate of 23.5 percent.

Even the most accurate trackers can still only provide an estimate of true calorie burn, said Brown, and it's not smart to base your refueling strategy entirely on their calculations.

"You also want to get in the habit of eating in response to hunger and stopping in response to comfortable fullness. This is dictated less by numbers and more by listening to your body,” she said.

Snack throughout the day
It may seem counterintuitive, but eating more throughout the day may be your ticket to consuming fewer calories overall, especially if you tend to pig out post-workout.

"Incorporating two to three healthy snacks throughout the day will help regulate hunger between meals, increase energy, and keep metabolism bumped up," White said.

Health.com: 20 Snacks That Burn Fat

Don't overestimate
You may feel like you burned a million calories during your Spin class, but research shows that we tend to overestimate our energy expenditure during exercise—by as much as four-fold, according to a study from the University of Ottawa. When volunteers were then asked to eat back all the calories they'd just burned, they tended to consume two to three times more than what they'd actually expended.

One high-tech way to prevent overestimating your calorie burn: wear a heart-rate monitor. Most of these include a sensor worn around your chest and a wristwatch, which sync together wirelessly. Still, if your heart-rate monitor says you burned 600 calories, that's not automatically an excuse to scarf down a 600-calorie sundae.

"If you are trying to lose weight, you will need to consume fewer calories than you expend," Brown said.

Drink water as soon as you're done
Replacing the fluids you lost during a workout should be priority number one, said Matt Fitzgerald, a certified sports nutritionist and author of Diet Cults and The New Rules of Marathon and Half-Marathon Nutrition.

"Having a lot of water in the belly also reduces appetite—not a lot, but a little," he said. "Guzzle water as soon as you walk in the door to quench your thirst and take up space in your tummy."

Just don't consume massive quantities. Taking in too much water (or any fluid) can cause water intoxication due to excessively low levels of salt in the body.

Health.com: 14 Surprising Reasons You're Dehydrated

Ask yourself if you really need to eat
You've probably heard that it's important to eat something immediately after your workout to help your muscles recover. But the truth is, you might not need to, said Brown. Say you've just finished up a tough run and you know you'd like to hit the gym for weight training in the morning. In that case, yes you should have something to eat.

"But if you're taking a few days off before your next hard workout, you probably don't need to worry about refueling quickly," Brown explained.

If you're not hungry, then don't force yourself to eat, she said.

"You're going to eat those calories eventually, so why not save them for your next meal when you're actually hungry?"

Refuel along the way
For workouts lasting longer than two hours—like a long bike ride or a marathon training run—sucking down a gel or sipping a sports drink will keep you from feeling ravenous afterward.

"Research has shown that people eat fewer calories after exercise when they take in carbs during exercise," Fitzgerald said. "In fact, their total calorie intake for the 24-hour period that includes the workout comes out to be slightly lower if they fuel up during it."

(Also important: You won't run out of steam halfway through your training session.) Try to consume 30 to 60 grams of carbs—that's 120 to 240 calories—every hour after your first hour. Avoid anything with protein, since it takes longer to for the stomach to digest.

This article originally appeared on Health.com.