Building muscle needs a modest surplus (~400 kcal over your daily burn), enough protein (1.6–2.2g per kg of bodyweight), and progressive training — in that order of maths, food, gym. This works out the calorie side with the Mifflin-St Jeor equation.
Your BMR (basal metabolic rate) is what your body burns doing nothing — calculated with the Mifflin-St Jeor equation, which studies consistently rate as the most accurate estimate for most people. Multiplying by your activity level gives your TDEE (total daily energy expenditure) — your real day-to-day burn.
To lose weight, eat ~500 kcal under your TDEE — roughly 0.5kg a week, sustainable for most people. To gain, eat ~400 over with enough protein. These are estimates: track for two or three weeks, watch the scales, and adjust by 100–200 kcal if the trend's off. That's exactly what Fuel Log's for.