Your body burns X calories per day to feed itself. If you eat less than this number, you will lose weight. Period. If you eat more than this number, you will gain weight. Period. Your TDEE or Total Daily Energy Expenditure can be easily estimated if your are so inclined, but it isn't necessary. Want to lose weight? Start at 2,000 calories per day. Monitor your weight across 4 weeks. If you aren't losing at a rate you're happy with, drop it to 1,800 calories per day. Repeat.
If you want to lose 5 lbs, you need a net deficit over time of 3500 * 5 = 17,500 calories.
Good/bad foods play a different role in your overall health, for example by impacting your level of water retention or satiety.