At the simplest level, of course it's calories in, calories out. Food (and drink) are sources of energy. Our body converts it into energy, but stores excess. At a defecift, it burns the storage. That's weight gain and weight loss in a nutshell. That's why diet is the most important issue: are you adding to your energy storage, or are you depleting it. Exercise is a great way to increase the energy you are burning, but biologically your body reacts by telling you to consume more energy. One of the things that's tough about weight loss is that your body reacts to burning storage and sends signals to your brain that you need to consume more. Being a mammal is tough like that. (That's not the only way.) But we do have agency. We can fight those impulses.
I weigh too much. Nearly always have. Even in the Army, when I was pretty damn fit, I carried around a little extra. I had one glorious moment lo about 10 years ago where I actually hit a number where I thought: solid; no need for anything more. That lasted about three months. I love food. It's probably my primary means of self medication. Stressed? Eat. Bored? Eat. Celebrate something? Eat. Basically, lots of eating. And after that magical moment, life came at me in waves, so I packed on some weight, and I've struggled to get back to where I'm happy (not even that magical moment happy, just happier).
I'm also pretty darned active. I average an hour of relativly high intensity cycling (I say relatively, because it's not the highest--I'm not doing big climbs) three times a week; I lift about twice a week (which is a relatively recent thing for me); and I do a combination (depending on the season) of refereeing soccer games (the big kids, so 80+ minutes each), golfing, and playing tennis during most of the year (and I'm an on and off runner). I used to be a hockey player, and I want to be again, but...time and convenience are a factor. The wild thing is that only recently did I give myself some grace and think, "yeah, you weigh too much, but you're also pretty darned active and reasonably strong, which is a good sign."
I should lose some weight. Among other things, I feel held back doing the athletics I want to do. I could run longer and faster as a referee, I would enjoy running more, and my joints would handle all of this stuff better than they do now. BUT...I can't beat myself up about it too much. And I really freakin' love ice cream.
(Sugar is my kryptonite--it, too, is addictive, which really freaking sucks, but not nearly as destructive as a bunch of other addictive things.)