First of all, there are a lot of articles all over the internet and various magazines telling you that you can gain muscle and lose weight at the same time if you just buy this supplement, do this routine, or what have you. These are lies, and I'm going to tell you why, and tell you the right way to accomplish these goals.
Ignore bodybuilders and models
For someone trying to live a normal lifestyle, there is no point following bodybuilders, watching what they do, and trying to copy their diet or exercise techniques. What they do is completely different from what an ordinary person trying to get fit needs to do. A professional bodybuilder does nothing but lift, eat, and prepare for competitions. This is not a normal person's lifestyle, and will not work if you are trying to get fit while having a job, a family to take care of, or a normal life.
Also, what you see on TV or in magazines or on the Internet is almost certainly an illusion. Without putting down the hard work these people do put into their bodies, usually the models have been airbrushed and photoshopped almost beyond recognition. In real life they aren't actually that big, or that cut, or that thin. Stop comparing yourself to the legs on that model, or the abs on that actor, because it's probably spraypainted, and if it is real, it's because that person spend six months dedicated to achieving that body.
Gaining muscle vs. losing weight
The difference between "bulking", and "leaning out", or gaining muscle and losing weight, is that when you're bulking, you need a calorie surplus, and when you're leaning out you need a calorie deficit. How can you do this at the same time? It's impossible. If your goals are to gain muscle and lose fat, you need to use a way of alternating between bulking up and leaning out that works for you. Some people alternate every three months, some alternate weekly, different people have different results.
For the best results, most people find three months of bulking followed by three months of losing weight to be effective. One reason for this is that when you have more muscle mass you burn more calories, so after a good period of muscle building, the cutting stage will be more effective and you will get more lean.
Now it is possible to build muscle without gaining weight, and to do that you need to be in the gym 4-5 days per week, for 45 minutes to an hour, putting some good stress on your muscles for bulking.
If you're trying to lean out or cut, it's all about burning. Your workouts need to be focused on burning as many calories as possible. Five or six days a week you need to do some kind of cardio, whether that be team sports, sprinting, running, biking, or elliptical machines.
Nutrition is extremely important to reaching your fitness goals. 80% of your results will come from nutrition and diet, the other 20% will come from your physical activity.
One area people trying to lose weight often trip up is calories in beverages. Our bodies aren't used to processing liquid calories, so we don't feel full after consuming them, but they will hurt you just as much if you're trying to lose weight. Stick to water, green tea, and cut out soda, juice, and other high-calorie beverages.
For building muscle, you need to consume more calories than you burn. It's important not to consume empty calories from sugars and sauces, and protein is necessary for building muscle, but without a calorie surplus you will not grow.
Two different goals
The truth is, you cannot gain muscle and lose weight at the same time, with a single diet and exercise program. It is possible to bulk up without gaining fat, and it's possible to lean down without losing muscle mass. To do both, you need a disciplined approach of alternating between a muscle building program and a fat cutting program.