How do you lose weight if you have to eat less and exercise more and compensate for the calories burned?

Just curious, but if you have to eat to lose weight, do you really lose weight? Obviously you need to eat less but why do they say to eat at a certain caloric intake?

I am trying to lose weight and I was informed that I need to take in 1001 calories a day. I ate 768 calories and burned 587 calories at the gym. Either way, I ate more than I burned. Can I still loose weight.

I am 5’5 145.