TDEE = BMR × Activity Factor, where BMR is computed using Mifflin-St Jeor and the activity factor reflects total weekly physical activity. The factors are: 1.2 (sedentary - desk job, no formal exercise), 1.375 (lightly active - light exercise 1-3 days/week or active job), 1.55 (moderately active - exercise 3-5 days/week or moderately active job), 1.725 (very active - exercise 6-7 days/week or physically demanding job), 1.9 (extremely active - competitive athlete with daily training, or hard physical labour + training).
For fat loss, subtract 500 kcal/day from TDEE for roughly 0.5 kg/week fat loss - sustainable for most adults. Larger deficits (750-1000 kcal/day) are appropriate only for obese individuals under supervision; smaller deficits (250-300 kcal/day) work for lean individuals trying to preserve muscle. Never eat below your BMR for more than a few days - the metabolic adaptation (lowered thyroid output, increased cortisol, decreased NEAT) makes fat loss progressively harder.
For muscle gain, add 200-500 kcal/day above TDEE - bigger surplus only if you're a true 'hardgainer' or competitive athlete. The optimal recomposition surplus is small (200-300 kcal) for trained lifters; larger surpluses (400-500 kcal) for beginner lifters who can recompose with both fat gain and muscle gain. Protein intake of 1.6-2.0 g/kg body weight is the other critical input for muscle gain.