Getting fat and losing fat comes down to a numbers game. I tell people all the time, it's quite simple. Gaining fat is when energy intake (food) is higher than what we burn through our metabolism and activity.
The law of conservation of energy states that "energy cannot be created or destroyed, but only changed from one form to another, or transferred from one object to one another." This means that the if we do not burn off the energy we take in, it will be stored in our bodies favorite way to do so, fat.
Overeating all types of macronutrients and calories types (carbohydrates, fats, proteins, and alcohol), or eating more than you expend, leads to fat storage in the body. There's no way around it.
There are other factors such as age, genetics and daily life movement that effect this as well. But, all in all, to lose fat you have to consistently take in fewer calories than you burn off.
If you seem to be adding fat or having a hard time losing it, track your food for a week on myfitnesspal. This will give you a good idea of where you are energy balance wise. Though calorie counting is never a perfect solution, doing this tends to bring awareness and numbers to the over-eating, under-moving patterns you've created.