Calories in Calories out, but that is only accurately calculable if you have an accurate idea of how many calories you are sending out, and if you are obese or formerly obese, the online calculators are likely not accurate for you at all.
One thing that is overlooked is that losing weight can permanently or at least semi-permanently decrease BMR, your Basal Metabolic Rate.
Your BMR is the calories you burn just to be alive, and is the foundation of almost every calorie counting system in the world.
At my worst, as a 33 year old 250lb 6'1" man, my BMR was at 1,836 Calories/day when it should have been at 2,133 Calories/day as diagnosed by a dexa scan and calorimetry test.
A 300 calorie a day decrease in my BMR from losing 100 lbs meant that I have to either find a way to increase my total metabolic burn or I have to permanently cut almost an entire meal from my diet for the rest of my life.
This was helpful and harmful in a way. It explained why when I was eating 500 calories a day under what my calculator said I should be eating I was barely losing a pound or two a month instead of a pound a week like I should have.
I was also tired and hungry all of the time, no energy, irritable and unhappy because so much weight loss had changed the way I function.
But when I quit the diet, I put on weight like crazy. I put on like 20 lbs in a couple of weeks and I didn't eat that much more than usual.
I've been checked for thyroid issues and diabetes, fortunately clear there, just a literally slowed metabolism as a consequence of losing 100 lbs.
There are things I can do to speed it back up, like going to the gym and putting on as much muscle as possible, but that also takes time and effort and work and it requires overeating and gaining weight at the same time.
Basically, once you're on a diet, you're always on a diet for the rest of your life, and the more weight you lose, the harder it becomes to lose weight if your metabolism is altered by your diet in the process.
If you're having trouble losing weight, get a Dexa scan and calorimetry test. That will identify where the fat is in your body and how many calories your body burns just sitting there doing nothing.
Once you have that data you can more accurately plan your diet to stay close to the 500 calorie/day limit to healthily lose weight. Just make sure you get re-scanned every 20 lbs or 6 months, it's not that expensive and gives you good information.