Even in a calorie deficit you can gain muscle if you do heavy weight lifting and eat enough protein daily. In fact, it’s very common for beginner lifters who have not done strength training workouts before. However, to build muscle mass effectively a calorie surplus is advised, while calorie deficit is a must for weight loss.