It's not impossible. But unless you've already done both with great success, you won't have the discipline and experience to even attempt to do both at the same time.
OP, here's some actual helpful generic advice:
Train like your gaining mass. Bust your balls. What worked to gain mass while in a caloric surplus will work to maintain mass in a deficit.
Go into a 400-800 calorie deficit. Eat a small meal containing carbs/protein 45 minutes before training, drink a gatorade (or similar carby sports drink) while training, and eat a big normal meal after.
Eat slightly less carbs on off days.
Do this consistently for 3 months. Report back with awesome before/after pictures.
If you're a newbie, you might gain some muscle. Don't count on it, though. But you will look better.
Such nonsense. There's no way that could always be the case. Is it 27g if I'm just doing arms? What if I did cardio after? What if I'm 150lb? What if I'm a lean 200lb bodybuilder? Male? Female? Leg day? What about my horomone profile? Is it optimal even if I have low T or high T? What about my cortisol levels?
Don't even think about optimizing it to that level; you're going to just set yourself up for failure when you can't do it. No need to be so anal.
I don't think cardio is actually strictly necessary for most people to lose fat if they're not trying to get super lean and can actually control their diet. If you stall on fat loss and calories are already low, just walking can do wonders. Don't go all gung ho out of the gate on cardio; again, you're just going to set yourself up for failure when you can't stick to it.
TLDR; train like you mean it, eat less food, be consistent, look better.