Your body has a certain amount of calories per day that it takes to MAINTAIN your current weight, this is your daily calorie maintenance. If you get less calories per day than that number, you will lose weight, if you get more than your daily maintenance you will gain weight.
Certain factors will determine what type of weight you gain or lose if you are above or below. You can't eat above your maintenance by eating candy bars and expect to gain muscle.
The same goes for losing weight, if you're not lifting heavy and eating properly when in a calorie defecient, you will lose muscle and maintain fat while dropping body weight.