The Math Behind Calorie Tracking
Every calorie tracker does arithmetic on your behalf. Most of them won't show you the equations. Here they are, with worked examples, in order, each building on the last.
This post covers five layers of calculation: how your baseline metabolism is estimated, how that estimate becomes a daily energy target, how the app learns your actual expenditure from real data, how food entries scale when you eat a partial serving, and how a calorie deficit translates into fat and lean tissue loss. Every number is traceable to an equation. Every equation is traceable to a cited source.
Layer 1: BMR estimation
Your Basal Metabolic Rate is the energy your body burns at complete rest: lying still, awake, in a temperature-neutral room. It accounts for roughly 60-70% of total daily expenditure.
The most widely validated formula is Mifflin-St Jeor (1990):
BMR (male) = 10 x weight(kg) + 6.25 x height(cm) - 5 x age + 5
BMR (female) = 10 x weight(kg) + 6.25 x height(cm) - 5 x age - 161
Each term captures a physiological relationship. Heavier bodies burn more energy (the weight term dominates). Taller bodies have more surface area and more metabolically active tissue. Metabolism declines with age. The sex offset accounts for differences in average body composition.
Worked example. A 30-year-old male, 82 kg, 178 cm:
10 x 82 = 820
6.25 x 178 = 1,112.5
5 x 30 = 150
sex offset = +5
BMR = 820 + 1,112.5 - 150 + 5 = 1,787.5 kcal
This is a population average. Mifflin-St Jeor was derived from indirect calorimetry measurements of 498 subjects. For any individual, the standard error is roughly ±200 kcal, meaning two people with identical stats can have BMRs that differ by 400 kcal. The formula gives you the center of the bell curve, not your personal measurement.
Source: Mifflin, M.D. et al. "A new predictive equation for resting energy expenditure in healthy individuals." American Journal of Clinical Nutrition, 1990.
Layer 2: from BMR to TDEE
BMR is the floor. Total Daily Energy Expenditure (TDEE) adds everything else: walking, working, exercising, digesting food, fidgeting. The traditional approach multiplies BMR by an activity factor:
| Activity Level | Multiplier | What it actually means |
|---|---|---|
| Sedentary | 1.200 | Desk job, minimal walking |
| Lightly Active | 1.375 | ~8,000 steps/day or light exercise 2x/week |
| Moderately Active | 1.550 | ~10,000 steps + resistance training 3x/week |
| Active | 1.725 | Physical job or training 5x/week |
| Very Active | 1.900 | Hard training daily + active lifestyle |
For our worked example (BMR = 1,788 kcal, lightly active):
TDEE = 1,788 x 1.375 = 2,458 kcal
The problem is obvious once you see it: the jump between levels is 0.175, which translates to ~310 kcal for a BMR of 1,788. That's an entire banana plus a tablespoon of peanut butter. If you pick the wrong activity level (and most people do), your TDEE estimate is off by hundreds of calories before you've logged a single meal.
Worse, the multipliers can't capture NEAT (Non-Exercise Activity Thermogenesis): fidgeting, posture, pacing, housework. NEAT alone varies by 700+ kcal/day between individuals with identical stats and exercise habits.
BMR / TDEE Calculator
Mifflin-St Jeor Equation
Layer 3: adaptive TDEE
Static formulas estimate what someone like you probably burns. Adaptive TDEE calculates what you actually burned, working backwards from what happened to your body.
The core insight: if you know how many calories you ate and how your weight changed over time, you can solve for expenditure.
The algorithm
Given a 28-day window of data:
Step 1. Average calorie intake across tracked days only. Days without food logs are excluded entirely (not counted as zero).
Step 2. Smooth daily weight readings with a 7-day Exponential Moving Average to filter out water, glycogen, and sodium noise. Then fit a least-squares linear regression to the smoothed series. The slope is your true weight trend in kg/day.
Step 3. Convert the weight slope to calories:
caloric impact = daily weight slope x 7,700 kcal/kg
The 7,700 kcal/kg figure is the standard approximation for the energy density of body tissue (a weighted mix of fat at ~7,700 and lean at ~1,800).
Step 4. Estimate TDEE:
TDEE = average daily intake - caloric impact
If you're losing weight, the caloric impact is negative, so TDEE comes out higher than intake. If you're gaining, it comes out lower. If weight is stable, TDEE equals intake.
Step 5. Clamp the daily adjustment to ±100 kcal from the previous estimate. This prevents noisy data from producing wild swings.
Worked example
Here's a real 28-day dataset for someone losing roughly 0.3 kg/week:
| Day | Weight (kg) | EMA (kg) | Calories | Tracked? |
|---|---|---|---|---|
| 1 | 82.3 | 82.30 | 2,180 | Yes |
| 4 | 82.5 | 82.35 | 2,210 | Yes |
| 7 | 81.8 | 82.15 | 2,050 | Yes |
| 10 | 82.0 | 81.96 | -- | No |
| 14 | 81.7 | 81.72 | 2,100 | Yes |
| 21 | 80.9 | 81.12 | 2,180 | Yes |
| 24 | 81.0 | 80.93 | 2,120 | Yes |
| 28 | 80.7 | 80.72 | 2,050 | Yes |
The calculation:
Average intake (tracked days): 2,150 kcal/day
EMA weight slope (regression): -0.042 kg/day
Caloric impact: -0.042 x 7,700 = -323 kcal/day
Estimated TDEE: 2,150 - (-323) = 2,473 kcal
This number reflects your actual metabolism: NEAT, adaptation, genetics, everything. No guessing your activity level.
Why 28 days
Daily weight fluctuates ±1 kg from water retention, glycogen stores, food mass in transit, and sodium intake. For someone losing 0.5 kg/week, the expected 14-day signal is ~1 kg, barely above the noise floor. A 28-day window captures ~2 kg of signal against the same noise, roughly doubling the signal-to-noise ratio.
For more detail on window length, EMA smoothing, and convergence behavior, see Why Your TDEE Calculator Is Probably Wrong.
Layer 4: macro scaling
When you log a food entry, you're rarely eating the exact serving size in the database. Macro scaling is the arithmetic that adjusts everything proportionally:
scaling factor = consumed amount / serving size
Every macro gets multiplied by the same factor. It's linear scaling.
Worked example. A database entry for oats: 100g serving, 389 kcal, 13.2g protein, 66.3g carbs, 6.9g fat. You ate 45g.
factor = 45 / 100 = 0.45
calories: 389 x 0.45 = 175.1 kcal
protein: 13.2 x 0.45 = 5.9g
carbs: 66.3 x 0.45 = 29.8g
fat: 6.9 x 0.45 = 3.1g
This is straightforward, but there's a subtlety that confuses people: the macros don't always add up to the calories.
The Atwater factors (4 kcal/g protein, 4 kcal/g carbs, 9 kcal/g fat) are approximations. The true values vary by food. Fiber contributes roughly 2 kcal/g, alcohol contributes 7 kcal/g, and neither is a standard macro. When a food database lists both total calories and macros, they often come from independent lab measurements. After rounding each macro to one decimal place and applying Atwater factors, the sum can differ from the listed calories by 5-15 kcal per serving. This compounds across a full day of logging.
This isn't a bug. It's the inherent imprecision of the Atwater system. The total calorie figure is more accurate than the sum of macro-derived calories, because the total is measured directly via bomb calorimetry or proximate analysis.
Layer 5: deficit math and body composition
The energy balance equation:
weight change = (intake - expenditure) / energy density of tissue
A 500 kcal/day deficit should produce 0.45 kg/week of weight loss if you use the standard 7,700 kcal/kg. But that number assumes all weight lost is fat. It isn't.
The Forbes/Hall model predicts what fraction of weight loss is fat versus lean tissue, based on how much fat you carry:
P-ratio = fat mass / (fat mass + 10.4)
P-ratio is the fraction of weight change that comes from fat. The constant 10.4 is empirically derived from body composition studies (Forbes 1987, refined by Hall 2007).
Higher body fat means a higher P-ratio, which means more of the loss is fat. Lower body fat means more lean tissue is sacrificed. This is why aggressive deficits at low body fat percentages are counterproductive: the math works against you.
Worked example. An 80 kg person at 22% body fat, running a 500 kcal deficit:
Fat mass: 80 x 0.22 = 17.6 kg
P-ratio: 17.6 / (17.6 + 10.4) = 0.629
Mixed density: 0.629 x 7,700 + 0.371 x 1,800 = 5,510 kcal/kg
Daily loss: 500 / 5,510 = 0.091 kg/day
Daily fat loss: 0.091 x 0.629 = 0.057 kg/day
Weekly total: 0.64 kg
of which fat: 0.40 kg (63%)
of which lean: 0.24 kg (37%)
Not 0.45 kg/week of pure fat. The real number depends on where you start.
At 35% body fat, the P-ratio is 0.77: nearly 80% of the loss is fat. At 12% body fat, it drops to 0.54: almost half the loss is lean tissue. Same deficit, different bodies, different outcomes.
P-Ratio Calculator
Body Composition
Energy Partitioning
Projected Loss
Sources: Forbes, G.B. "Lean body mass-body fat interrelationships in humans." Nutrition Reviews, 1987. Hall, K.D. "Body fat and fat-free mass inter-relationships." British Journal of Nutrition, 2007.
Where you'll see this in the app
These are the equations running inside Onyx Tenet. Here's what they look like in practice.
The TDEE card shows both the formula estimate and the adapted value, with a confidence badge and data coverage stats. The TDEE Trajectory chart plots how the estimate has evolved over time. In this example, the adaptive TDEE (2,163 kcal) closely matches the formula estimate (2,172 kcal), confirmed by 26 weigh-ins and 28 tracked days.

The weekly summary applies the energy balance equation from Layer 5. Average intake (1,991 kcal) minus average TDEE (2,254 kcal) gives a daily deficit of 263 kcal, which projects to -0.24 kg/week of weight change. Each day's macros are visible in the breakdown below.

Every number traces back to one of the equations above. No black boxes.
Adaptive TDEE in Onyx Tenet is free. It activates automatically after about 4 weeks of logging and weighing. No subscription required.