Spoiler alert: you cannot.
Not unless you are a rank beginner (less than six months training), are very overweight, or using a lot of illegal substances.
This is consistent with the first law of thermodynamics, which states that energy can neither be created nor destroyed, only changed from one form to another. Simply stated, take in more calories than you expend and the excess energy will be stored in the form of body mass.
By the same token, if you take in fewer calories than you are using up through training, that energy will also come from your body mass, ideally the fat cells.
In an attempt to do both, trainees are chasing two polar opposite sides of the spectrum and end up achieving neither.
What about training for fat loss?
Training does not change whether your goal is hypertrophy or fat loss. When you are eating fewer calories than you are using, you body will look into alternate energy sources to feed itself. If the muscle is not being used, the body will use it up for energy thereby setting you sup to be a skinny-fat person. Sad.
If you are lifting heavy things, your body will see the need to keep the muscle on and you are on your way to ultimate jackedness.
When it comes to cardio, the road parts. Excessive cardio down regulates the ability to build muscle by shifting several signaling pathways in the body, so when you are trying to get bigger, keep it to 3×30 minutes at most.
How much should you eat when bulking?
18-20 calories per lbs of bodyweight is a good yardsticks so a hypothetical 200 lbs lifter would be eating anywhere from 3600 to 4000 calories. Fun!!
Ectomorphs can be a bit higher in carbs, endomorphs could consume more fats while staying in the same caloric range.
Muscle growth happens at best at about 2 lbs a month, so whatever you are gaining on top of that is not muscle.
When it comes too fat loss, the opposite applies. You set your calories as follows:
Goal weight x (10 for females/ 11-12 for males + number of hours of lifting)
For instance, if you are 200 lbs male, want to weigh 180, train 4 hours a week, you would eat 180 x (11 + 4) = 2,700 calories per day.
If the same person at 200 lbs was trying to bulk, he would be eating 200×20=4000 calories per day.
And this, ladies and gentlemen, is why you can not do it both.