The key to this is not skimping on calories on purpose. If you do, you run the risk of slowing your metabolism, meaning if you want to lose weight you have to eat even less, and then your metabolism will slow down even more, in order to compensate. . . . that way lies madness and perpetual hunger.
So the easiest way to handle this is to eat to satiety. In other words, wait till you’re hungry to eat, eat enough to satisfy your hunger, and stop eating when you stop being hungry. This way you can be sure that you are getting enough, without overdoing it. Your metabolism will rise to match the energy you give it, and if you happen to have any excess fat stored about your body, your appetite will set itself to use both the fat you eat and the extra stored fat.
Caloric calculations are tricky. First of all, the heat content of food is a poor measure of what we are eating; it’s left over from the nineteenth century, when burning food to measure its heat content was all we knew how to do. But we’re stuck with it now. Secondly, the caloric values bandied about (4/g of carb and protein, 9/g of fat) are not precise values; they are rounded to the nearest integer. Not only that, but different foods contain slightly different heat (caloric) values.
The next difficulty lies in coming up with a good estimate of your energy expenditure. There are apps that will give you a figure, but there is no way that figure can be accurate, since your physiology is unique. The only really accurate way to measure your energy expenditure is to spend 24 hours in a metabolic chamber, but that only tells you what your energy expenditure was that day; it could be quite different from day to day.
Lastly, according to the energy-intake hypothesis of obesity, you have to match your intake and your expenditure to within 20 calories, in order to avoid losing or gaining weight. Fortunately, for us, the actual science shows that the types of food we eat make a big difference in what our body does with what we eat, and a well-formulated ketogenic diet works in such a way as to make it possible for us to use our appetite as a guide to how much to eat, making all these calculations unnecessary. Studies have shown that our appetite and our activity may not match very closely on any given day, but they do match pretty precisely over a seven- or eight-day period.