Calculate your optimal macronutrient ratios for the ketogenic diet.
Male
Female
Sedentary (little to no exercise)
Lightly Active (light exercise/sports 1-3 days/week)
Moderately Active (moderate exercise/sports 3-5 days/week)
Very Active (hard exercise/sports 6-7 days/week)
Extra Active (very hard exercise/sports & physical job)
Weight Loss
Maintain Weight
Gain Muscle
Understanding Your Keto Macros
The ketogenic diet is a very low-carbohydrate, high-fat diet that puts your body into a metabolic state called ketosis.
When your body is in ketosis, it becomes very efficient at burning fat for energy. This calculator helps you determine
your personalized macronutrient targets (protein, fat, and carbohydrates) based on your individual characteristics and goals.
How It Works: The Math Behind the Calculation
This calculator utilizes standard formulas to estimate your Basal Metabolic Rate (BMR) and Total Daily Energy Expenditure (TDEE),
and then adjusts these based on your dietary goal and the principles of the ketogenic diet.
1. Basal Metabolic Rate (BMR)
BMR is the number of calories your body needs to perform basic life-sustaining functions at rest. We use the Mifflin-St Jeor Equation,
which is considered one of the most accurate for estimating BMR:
For Men: BMR = (10 × weight in kg) + (6.25 × height in cm) – (5 × age in years) + 5
For Women: BMR = (10 × weight in kg) + (6.25 × height in cm) – (5 × age in years) – 161
2. Lean Body Mass (LBM)
LBM is crucial for determining protein intake, as protein needs are based on lean mass, not total weight.
LBM = Weight in kg × (1 – (Body Fat Percentage / 100))
3. Total Daily Energy Expenditure (TDEE)
TDEE accounts for your BMR plus the calories burned through physical activity. We multiply BMR by an activity factor:
Sedentary: BMR × 1.2
Lightly Active: BMR × 1.375
Moderately Active: BMR × 1.55
Very Active: BMR × 1.725
Extra Active: BMR × 1.9
4. Macronutrient Calculation for Ketogenic Diet
On a ketogenic diet, macronutrient ratios are typically:
Carbohydrates: 5-10% of total calories (usually capped at 20-50g net carbs per day for most individuals to ensure ketosis)
Protein: 15-25% of total calories, primarily based on Lean Body Mass (around 1.2-1.7g per kg of LBM is a common target).
Fat: The remaining percentage of calories (typically 70-80%).
The calculator adjusts the target calories based on your goal:
Weight Loss: TDEE – 500 calories (creates a deficit for fat loss).
Maintain Weight: TDEE (no calorie adjustment).
Gain Muscle: TDEE + 250-500 calories (creates a surplus for muscle growth).
Using the target calories and the chosen macronutrient percentages (with a strict carb limit and LBM-based protein), the calculator determines your grams of protein, fat, and net carbs per day.
Why Use This Calculator?
Personalizing your keto macros is essential for success. While general guidelines exist, factors like age, gender, activity level, body composition, and specific goals (weight loss, maintenance, muscle gain) significantly influence your nutritional needs. This calculator provides a data-driven starting point to help you optimize your ketogenic journey, ensuring you get adequate protein to preserve muscle, sufficient fat for energy, and just enough carbs to stay in ketosis.
function calculateMacros() {
var weight = parseFloat(document.getElementById("weight").value);
var height = parseFloat(document.getElementById("height").value);
var age = parseFloat(document.getElementById("age").value);
var gender = document.getElementById("gender").value;
var activityLevel = document.getElementById("activityLevel").value;
var bodyFat = parseFloat(document.getElementById("bodyFat").value);
var goal = document.getElementById("goal").value;
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = "; // Clear previous results
// Input validation
if (isNaN(weight) || weight <= 0 ||
isNaN(height) || height <= 0 ||
isNaN(age) || age <= 0 ||
isNaN(bodyFat) || bodyFat 100) {
resultDiv.innerHTML = "Please enter valid positive numbers for all fields.";
return;
}
// 1. Calculate BMR (Mifflin-St Jeor Equation)
var bmr;
if (gender === "male") {
bmr = (10 * weight) + (6.25 * height) – (5 * age) + 5;
} else { // female
bmr = (10 * weight) + (6.25 * height) – (5 * age) – 161;
}
// 2. Calculate Activity Factor
var activityFactor;
switch (activityLevel) {
case "sedentary":
activityFactor = 1.2;
break;
case "light":
activityFactor = 1.375;
break;
case "moderate":
activityFactor = 1.55;
break;
case "very_active":
activityFactor = 1.725;
break;
case "extra_active":
activityFactor = 1.9;
break;
default:
activityFactor = 1.2; // Default to sedentary
}
// 3. Calculate TDEE
var tdee = bmr * activityFactor;
// 4. Adjust TDEE based on goal
var targetCalories;
if (goal === "lose_weight") {
targetCalories = tdee – 500;
} else if (goal === "maintain") {
targetCalories = tdee;
} else { // gain_muscle
targetCalories = tdee + 300; // Moderate surplus for muscle gain
}
// Ensure target calories are not excessively low, especially for muscle gain or maintenance
if (targetCalories < 1200) {
targetCalories = 1200; // Minimum reasonable calorie intake
}
// 5. Calculate Lean Body Mass (LBM)
var lbmKg = weight * (1 – (bodyFat / 100));
// Ensure LBM is not negative or greater than total weight (edge cases)
if (lbmKg weight) lbmKg = weight;
// 6. Determine Macronutrient Targets
// Keto Macro Ratios (flexible, but commonly):
// Carbs: ~5% (or a fixed gram limit like 20-30g net)
// Protein: ~20-25% (but primarily based on LBM)
// Fat: ~70-75%
// Protein: Aim for 1.2-1.7g per kg of LBM. Let's use a moderate value like 1.5g/kg.
var proteinGrams = lbmKg * 1.5;
// Adjust protein slightly if it leads to excessively high fat or very low fat
if (goal === "lose_weight" && proteinGrams * 4 > targetCalories * 0.25) {
proteinGrams = targetCalories * 0.25 / 4; // Cap protein at 25% if needed for deficit
}
if (proteinGrams * 4 > targetCalories * 0.30) { // Ensure protein doesn't exceed 30% generally
proteinGrams = targetCalories * 0.30 / 4;
}
// Ensure minimum protein intake
if (proteinGrams < 50) proteinGrams = 50; // Minimum reasonable protein
var proteinCalories = proteinGrams * 4; // 4 calories per gram of protein
// Net Carbs: Aim for 20-30g net carbs for ketosis. Let's use 25g as a standard.
var carbGrams = 25; // Fixed net carbs for ketosis
var carbCalories = carbGrams * 4; // 4 calories per gram of carb
// Fat: Remaining calories
var fatCalories = targetCalories – proteinCalories – carbCalories;
var fatGrams = fatCalories / 9; // 9 calories per gram of fat
// Ensure fat grams are not negative. If they are, we need to adjust other macros or target calories.
// This can happen if protein+carb calories exceed target calories, which is unlikely with standard keto ratios but good to check.
if (fatGrams targetCalories) {
// If protein and carbs alone exceed target, we have a problem.
// This scenario is rare but possible with very low target calories.
// We might need to slightly reduce protein or carbs, or increase target calories.
// For now, let's just display a warning/modified result.
// Re-calculate protein and carb grams based on percentages if needed, but the LBM/fixed carb approach is more standard.
// A safer fallback is to slightly increase target calories or reduce protein/carbs.
// Let's cap fat at 0 and inform the user implicitly via the output.
} else {
fatCalories = targetCalories – totalNonFatCalories;
fatGrams = fatCalories / 9;
}
}
// Format the results
var resultHTML = "Your Daily Macronutrient Targets:";
resultHTML += "";
resultHTML += "Calories: " + targetCalories.toFixed(0) + " kcal";
resultHTML += "Protein: " + proteinGrams.toFixed(0) + "g";
resultHTML += "Net Carbs: " + carbGrams.toFixed(0) + "g";
resultHTML += "Fat: " + fatGrams.toFixed(0) + "g";
resultHTML += "";
resultDiv.innerHTML = resultHTML;
}