The basics:

Our bodies get energy from the food we eat. The unit of energy provided by food is known as a Calorie (US, Canada) or kcal (worldwide). The amount of energy provided by various nutrients is:

Protein 4 kcal/gram
Carbohydrates (other than fiber)
    Insoluble Fiber
    Soluble Fiber
4 kcal/gram
0 kcal/gram
2 kcal/gram
Fats 9 kcal/gram
Alcohol 7 kcal/gram

If we consume more calories than we use for energy, we will gain weight. If we consume fewer calories than we use for energy, we will lose weight.

Note: For those of you who will notice - Although technically not correct, I often use calories with a little 'c' to denote Calories with a big 'C'.

The details:

Although the basic ‘calories in versus calories out‘ principle is always true, there are some details to keep in mind.

Caloric needs go down as your weight goes down

To demonstrate this, read the following example:

Alice is a 25 year old female who is 5'5 and 150 lbs. She bikes to and from work for a total of 30 minutes/day of moderate activity.
She uses the caloric needs calculator, to determine that she needs approximately 2294 kcal/day to maintain her weight. She goes on a diet, reducing her intake to 2000 kcal/day, while keeping the same activity level, and after 4 months she has lost 10 pounds.
We put her new information into the caloric needs calculator, and determine that she now needs 2237 calories to maintain her current weight. If she returns to her previous maintenance of 2294 calories, she will gain weight slowly! This is because it takes fewer calories (57 in this case) to perform the same activities at her new bodyweight. While 57 extra calories does not seem like much, that is enough to make you gain 6 pounds in a year.

I recommend that when you are trying to either lose weight, or gain muscle, you recalculate your caloric needs for every 10 pounds lost or gained.

The risk of permanent metabolic slowdown in obese individuals is overblown

A study done by Wadden et al which tracked resting metabolic rate changes in obese patients over 48 weeks of dieting did not ‘show a suppression of RMR (resting metabolic rate) as normalised to fat free mass or body weight’. That is, the metabolic slowdown was shown to be reversible upon resuming higher calorie diets, and their RMR was not lower than would be expected at their new body weight.

Having a thyroid condition does not violate ‘calories in vs. calories out’

If you have hypothyroidism, your resting metabolic rate decreases. This means that the number of calories it takes to maintain your weight goes down. If you eat less than your maintenance level, you will still lose weight. The bottom line here is that you will need to consume fewer calories than you would if you did not have this condition - this is an additional reason for your meals to be of high nutritive value.

Similarly, if you have hyperthyroidism, your resting metabolic rate increases. This means that the number of calories it takes to maintain your weight goes up. If you eat more than your maintenance level, you will still gain weight.

Note: You should seek treatment from your doctor if you have an over/under-active thyroid. It will be easier to reach your ideal body weight if you receive treatment.

Additional Reading