The energy values
Every macro calculation rests on three numbers: protein 4 kcal/g, carbohydrate 4 kcal/g, fat 9 kcal/g. From a calorie target, the share assigned to each macro is converted to grams by dividing by the relevant value.
A worked example
Take 2,200 kcal with a 30/40/30 split. Protein: 30% of 2,200 is 660 kcal, divided by 4, gives 165 g. Carbohydrate: 40% of 2,200 is 880 kcal, divided by 4, gives 220 g. Fat: 30% of 2,200 is 660 kcal, divided by 9, gives about 73 g.
Protein first
Protein has the strongest evidence for body composition, so set it from body weight rather than as a percentage. For general health 1.2–1.6 g/kg; for building muscle 1.6–2.2 g/kg; during a fat-loss diet 1.6–2.4 g/kg to protect muscle. Spread it across three to five servings of roughly 0.3–0.4 g/kg.
Fat as a minimum, carbs as the remainder
Fat supports hormones and vitamin absorption, so keep a floor of roughly 0.6–1 g/kg. Carbohydrate is the flexible macro: assign it whatever calories are left after protein and fat, which naturally means more carbs on training days and fewer on rest days.
Common splits
Balanced (30/40/30), low carb (35/25/40), high protein (40/35/25), keto (25/5/70) and endurance (25/55/20) are the main patterns. None is uniquely best; adherence matters more than the exact ratio, and protein should stay high in all of them.
When you cannot hit every number
Prioritise in order: hit your protein, keep calories within about 100 kcal of target, and let carbohydrate and fat trade off within the budget. Logging apps make this easy once the targets are set.