The problem with dieting is that it's much more complicated than counting calories.
There are a ton of studies out there that prove that starving yourself by dieting will lead to short term weight reduction, but in the long term it will increase your weight.
Since a couple of years we know that dieting changes your hormone system and your gut bacteria. Basically you (and your gut bacteria) become more efficient in extracting energy from your food. So when you finish dieting and return to your previous level of eating, you will put on weight because you take in too much energy and your body is eager to store it because from the perspective of your body you just had a starvation crisis, so it thinks better be ready for next time.
Also genetics play a huge role here. If you are predisposed the be stocky, you will probably never will be skinny for a lengthy amount of time in your adult life.
Genetics is also the reason why some people have so much success when they try keto or paleo. Our diet is less protein-rich than it was 30 or 50 years ago. But because of genetics a considerate amount of the population needs more proteins in their diet than a common diet will provide So when eating food that is low on proteins they constantly feel hungry. Even if they already ate more calories than they need, they will keep on eating until their body thinks it's got enough proteins. If you are constantly having an appetite for hearty food, you are probably in this group.
There a couple of other thing to look out for when you want to loose weight or don't want to put on weight. Avoid light products. Avoid artificial sweeteners (some are proven to mess up the hormone system, also they are used to fatten piglets). Avoid convenience food with a lot of emulsifying agents (believed to mess up gut bacteria), prefer home-cooked meals, learn to cook if necessary. Avoid low-fat products (like low-fat milk, not products that have no fat in the first place). Mostly avoid soft drinks, prefer soft drinks with sugar instead of artificial sweeteners if you must. Mostly avoid fruit juice. Mostly avoid alcohol (prefer wine to beer). Actually mostly avoid any beverages with a lot of calories. Probably avoid corn syrup or high-fructose syrup. Try to eat 3 meals a day (and nothing in between). Don't eat food because you think it's 'healty', eat food that you like and that agrees with you. Make sure your diet contains enough protein and fat (I'm not getting in the good fat vs bad fat mine field here, but probably avoid trans fatty acids). Exercise 3-5 times a week for an hour (light to moderate exercise), prefer muscle training to cardio, at least 2:1. Stay active, use your bike or walk instead of using your car if you can, avoid elevators, use stairs if you can, etc. Try to have at least 6 hours of restful sleep every night.
From the top of my head this a is selection of advice that has been medically validated in the last years, at least until new studies come along that tell us otherwise. Of course your mileage may vary, because genetics and personal circumstances.