Sorry for asking a question that has no doubt been asked many times before but I am confused .

I had the understanding that to gain muscle you need to have a calorie surplus and to lose fat you need to have a calorie deficit .This is what makes doing both at the same time impossible without the use of steroids

However it seems that both can be done at the same time

My question is who can lose fat and gain muscle at the same time? For example do you need to have a large amount of body fat or be a beginner?

What it is the required diet to achieve both these goals at the same time?