Macro Calculator
Calculate daily carbohydrate, protein, and fat targets based on your calorie goal.
Macro Calculator computes your daily recommended intake of the three macronutrients — protein, carbohydrates, and fats — based on your calorie target and fitness goal. Macronutrients are the energy-providing components of food: protein provides 4 calories per gram, carbohydrates 4 calories per gram, and fat 9 calories per gram.
Enter your daily calorie goal, body weight, and primary fitness goal (fat loss, maintenance, or muscle gain). The tool applies evidence-based macro ratios: for muscle gain, a higher protein target (around 1.6-2.2g per kg of body weight) with adequate carbs for energy and a moderate fat intake; for fat loss, protein stays high to preserve muscle while fats and carbs are adjusted.
Macro targets are guidelines, not absolute rules. Individual response varies, and factors like food preferences, digestion, and training style all play a role. Many people find tracking macros for a few weeks builds enough nutritional awareness to intuitively eat well without strict counting.
Frequently Asked Questions
Code Implementation
def calculate_macros(weight_kg: float, height_cm: float, age: int,
sex: str, activity: float, goal: str) -> dict:
"""
Calculate TDEE and macronutrient targets using Mifflin-St Jeor BMR.
sex: 'male' or 'female'
activity: 1.2=sedentary, 1.375=light, 1.55=moderate, 1.725=active, 1.9=very active
goal: 'lose' (-500 kcal), 'maintain', 'gain' (+300 kcal)
"""
if sex == "male":
bmr = 10 * weight_kg + 6.25 * height_cm - 5 * age + 5
else:
bmr = 10 * weight_kg + 6.25 * height_cm - 5 * age - 161
tdee = bmr * activity
adjustment = {"lose": -500, "maintain": 0, "gain": 300}.get(goal, 0)
target_calories = tdee + adjustment
# Macro splits (lose: 40/35/25, maintain: 35/40/25, gain: 30/45/25)
splits = {"lose": (0.40, 0.35, 0.25), "maintain": (0.35, 0.40, 0.25), "gain": (0.30, 0.45, 0.25)}
p_ratio, c_ratio, f_ratio = splits.get(goal, (0.35, 0.40, 0.25))
protein_g = target_calories * p_ratio / 4
carbs_g = target_calories * c_ratio / 4
fat_g = target_calories * f_ratio / 9
return {
"bmr": round(bmr), "tdee": round(tdee),
"target_calories": round(target_calories),
"protein_g": round(protein_g), "carbs_g": round(carbs_g), "fat_g": round(fat_g),
}
r = calculate_macros(70, 175, 30, "male", 1.55, "lose")
print(f"BMR : {r['bmr']} kcal")
print(f"TDEE : {r['tdee']} kcal")
print(f"Target Calories : {r['target_calories']} kcal")
print(f"Protein : {r['protein_g']} g")
print(f"Carbs : {r['carbs_g']} g")
print(f"Fat : {r['fat_g']} g")Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.