Changing your body is a process, a science and a numbers game. To build muscle while minimizing fat gain you need to have a firm understanding of how many calories to consume on a daily basis.
There are many ways to determine caloric balance for weight loss, maintenance and gain, but the below is pretty straightforward and a good rule of thumb without additional equipment or tests for measurement.
Current bodyweight * 10-13 (calories per pound)
Current bodyweight * 14-16 (calories per pound)
Current bodyweight * 17-19 (calories per pound)
For example, I weigh 140 pounds and at any given point in time am most likely trying to shed fat (while building muscle). I tend to consume 12 calories per pound (1,680 calories).
As mentioned, changing your body is a process, a science and a number games. Unfortunately, it’s not one-size fits all and it can change in a blink due to circumstances like workouts, weather, travel, stress, etc. You’ll need to take time (and it takes time, like weeks) to find your sweet spot. But when you do you’ll be set up for success to reach your fitness goals.