The energy that you expend can be broken down into three categories:
Resting metabolic rate, also known as your BMR. This is the amount of energy you burn at rest (doing nothing). This can be found (very roughly) using a BMR calculator, like this one: http://www.bmrcalculator.org
Thermic effect of food. This is the amount of energy you expend processing and digesting the food you eat. Protein requires up to 30% of its calories to digest, carbohydrates require up to 10% to digest, fats require up to 3% to digest.
Physical exercise activity. This is the amount of energy you expend being active, moving around, exercising, etc.
This produces the full energy balance equation:
The energy you consume - resting metabolic rate - thermic effect of food - physical activity expenditure = energy remaining
If the energy you consume is more than these three combined, you gain weight.
If the energy you consume is less than these three combined, you lose weight.