Sedentary (little or 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 a week)
Extra active (very hard exercise/sports & physical job or 2x training)
Weight Loss
Weight Maintenance
Muscle Gain
Your Keto Macros
Total Daily Calories:
Protein (g):
Carbohydrates (g):
Fat (g):
Understanding Ketogenic Diet Macros
The ketogenic diet, often referred to as "keto," is a very low-carbohydrate, high-fat diet. The primary goal is to shift the body's metabolic state from using glucose (from carbohydrates) for energy to using ketones (produced from fat). This state is known as ketosis.
To achieve and maintain ketosis, it's crucial to carefully manage your macronutrient intake. Macronutrients (macros) are the nutrients your body needs in large amounts: carbohydrates, protein, and fat. This Keto Macro Calculator helps you determine the optimal grams of each macro based on your personal details and goals.
How the Keto Macro Calculator Works
This calculator uses standard formulas to estimate your daily calorie needs and then breaks them down into keto-specific macronutrient targets.
1. Basal Metabolic Rate (BMR) Calculation:
First, your Basal Metabolic Rate (BMR) is estimated. This is the number of calories your body burns at rest to maintain basic functions. We use the Mifflin-St Jeor equation, which is widely considered accurate:
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. Total Daily Energy Expenditure (TDEE) Calculation:
Your BMR is then multiplied by an activity factor to estimate your Total Daily Energy Expenditure (TDEE) – the total calories you burn in a day, including physical activity.
TDEE = BMR × Activity Factor
Sedentary: 1.2
Lightly active: 1.375
Moderately active: 1.55
Very active: 1.725
Extra active: 1.9
3. Calorie Adjustment for Goal:
Your TDEE is adjusted based on your chosen goal:
Weight Loss: A deficit of typically 15-20% is applied to the TDEE.
Weight Maintenance: TDEE remains as calculated.
Muscle Gain: A surplus of typically 10-15% is added to the TDEE.
4. Macronutrient Distribution:
Finally, the target daily calorie intake is divided among the macronutrients according to your specified percentages:
Protein (g) = (Target Daily Calories × Protein Percentage) / 4
Note: Protein and carbohydrates provide 4 calories per gram, while fat provides 9 calories per gram.
Why Macro Tracking is Important on Keto
On a ketogenic diet, carbohydrate intake is strictly limited (typically to 20-50 grams per day) to induce ketosis. Protein intake should be adequate for muscle preservation and repair but not excessive, as the body can convert excess protein into glucose (gluconeogenesis). Fat becomes the primary source of energy, hence the high-fat percentage.
Using this calculator provides a personalized starting point for your keto journey. Remember to listen to your body and adjust your intake as needed. Consulting with a healthcare professional or a registered dietitian is always recommended when making significant dietary changes.
function calculateMacros() {
var bodyWeight = parseFloat(document.getElementById('bodyWeight').value);
var heightCm = parseFloat(document.getElementById('heightCm').value);
var age = parseFloat(document.getElementById('age').value);
var gender = document.getElementById('gender').value;
var activityLevel = document.getElementById('activityLevel').value;
var ketoGoal = document.getElementById('ketoGoal').value;
var carbPercentage = parseFloat(document.getElementById('carbPercentage').value);
var proteinPercentage = parseFloat(document.getElementById('proteinPercentage').value);
var fatPercentage = parseFloat(document.getElementById('fatPercentage').value);
var errorDiv = document.getElementById('calculatorError');
var resultContainer = document.getElementById('resultContainer');
errorDiv.textContent = ";
resultContainer.style.display = 'none';
// — Input Validation —
if (isNaN(bodyWeight) || bodyWeight <= 0) {
errorDiv.textContent = 'Please enter a valid body weight in kg.';
return;
}
if (isNaN(heightCm) || heightCm <= 0) {
errorDiv.textContent = 'Please enter a valid height in cm.';
return;
}
if (isNaN(age) || age <= 0) {
errorDiv.textContent = 'Please enter a valid age.';
return;
}
if (isNaN(carbPercentage) || carbPercentage 100) {
errorDiv.textContent = 'Carbohydrate percentage must be between 0 and 100.';
return;
}
if (isNaN(proteinPercentage) || proteinPercentage 100) {
errorDiv.textContent = 'Protein percentage must be between 0 and 100.';
return;
}
if (isNaN(fatPercentage) || fatPercentage 100) {
errorDiv.textContent = 'Fat percentage must be between 0 and 100.';
return;
}
var totalPercentage = carbPercentage + proteinPercentage + fatPercentage;
if (Math.abs(totalPercentage – 100) > 1) { // Allow for small floating point inaccuracies
errorDiv.textContent = 'The sum of Carbohydrate, Protein, and Fat percentages must equal 100%.';
return;
}
// — BMR Calculation (Mifflin-St Jeor) —
var bmr = 0;
if (gender === 'male') {
bmr = (10 * bodyWeight) + (6.25 * heightCm) – (5 * age) + 5;
} else { // female
bmr = (10 * bodyWeight) + (6.25 * heightCm) – (5 * age) – 161;
}
// — Activity Factor —
var activityFactor = 1.0;
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;
}
// — TDEE Calculation —
var tdee = bmr * activityFactor;
// — Calorie Adjustment for Goal —
var targetCalories = tdee;
if (ketoGoal === 'weight_loss') {
targetCalories = tdee * 0.85; // ~15% deficit
} else if (ketoGoal === 'muscle_gain') {
targetCalories = tdee * 1.10; // ~10% surplus
}
// For 'maintenance', targetCalories remains tdee
// Ensure target calories are reasonable
if (targetCalories < 1000) {
targetCalories = 1000; // Minimum reasonable calories
if (ketoGoal === 'muscle_gain') targetCalories = 1500; // Minimum for muscle gain
}
// — Macronutrient Calculation —
var proteinGrams = (targetCalories * (proteinPercentage / 100)) / 4;
var carbGrams = (targetCalories * (carbPercentage / 100)) / 4;
var fatGrams = (targetCalories * (fatPercentage / 100)) / 9;
// Round to 1 decimal place for grams, 0 for calories
proteinGrams = Math.round(proteinGrams * 10) / 10;
carbGrams = Math.round(carbGrams * 10) / 10;
fatGrams = Math.round(fatGrams * 10) / 10;
var roundedTargetCalories = Math.round(targetCalories);
// — Display Results —
document.getElementById('totalCalories').textContent = roundedTargetCalories + ' kcal';
document.getElementById('proteinGrams').textContent = proteinGrams + ' g';
document.getElementById('carbGrams').textContent = carbGrams + ' g';
document.getElementById('fatGrams').textContent = fatGrams + ' g';
resultContainer.style.display = 'block';
}