Macronutrient Calculator
Calculate daily protein, carbs, and fat targets based on your calorie goal. Supports Balanced, Keto, Low Carb, and custom ratios.
About this tool
The Macronutrient Calculator turns a daily calorie target into concrete gram goals for protein, carbohydrates, and fat. Instead of guessing how a number of calories should break down across each macro, you get clear targets you can actually shop and cook by.
Enter your daily calorie goal and pick a macro split such as balanced, low-carb, or high-protein. The tool instantly shows how many grams of protein, carbs, and fat that split implies, which makes it handy for meal planning, cutting or bulking, and tracking your day in a food app.
Macronutrient needs vary from person to person depending on body, activity level, and goals, so treat these numbers as a starting point rather than medical or dietetic advice. Everything runs locally in your browser, so your calorie goal and results never leave your device.
Frequently Asked Questions
Code Implementation
def calculate_macros(calories, protein_pct, carbs_pct, fat_pct, meals=3):
"""
Calculate macronutrient grams from daily calorie goal.
Protein & carbs: 4 kcal/g, Fat: 9 kcal/g
"""
if abs(protein_pct + carbs_pct + fat_pct - 100) > 0.5:
raise ValueError("Percentages must add up to 100")
protein_kcal = calories * protein_pct / 100
carbs_kcal = calories * carbs_pct / 100
fat_kcal = calories * fat_pct / 100
protein_g = protein_kcal / 4
carbs_g = carbs_kcal / 4
fat_g = fat_kcal / 9
return {
"daily": {"protein": round(protein_g, 1), "carbs": round(carbs_g, 1), "fat": round(fat_g, 1)},
"per_meal": {"protein": round(protein_g / meals, 1),
"carbs": round(carbs_g / meals, 1),
"fat": round(fat_g / meals, 1)},
"calories": {"protein": round(protein_kcal), "carbs": round(carbs_kcal), "fat": round(fat_kcal)},
}
PRESETS = {
"balanced": (30, 40, 30),
"low_carb": (40, 20, 40),
"keto": (35, 5, 60),
"high_protein":(45, 35, 20),
}
# Example: 2000 kcal keto diet, 3 meals
result = calculate_macros(2000, *PRESETS["keto"], meals=3)
print("Daily macros:", result["daily"])
print("Per meal: ", result["per_meal"])Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.