Your body only operates in three calorie states. A calorie deficit, maintenance calories, or a calorie surplus.
If you eat fewer calories than your body burns, you lose weight because your body has to use stored energy, which usually comes from body fat. If you eat the same amount of calories that your body burns, your weight stays about the same. If you eat more calories than your body burns, your body stores that extra energy and you gain weight.
The only way to lose fat is to be in a calorie deficit. The only way to gain weight is to be in a calorie surplus. The only way to lose fat and build muscle at the same time is to train with weights, eat enough protein, and stay around maintenance calories or a small deficit so your body can use stored fat for energy while building muscle.
Tracking your food becomes very important if you want to get really lean. When you track what you eat, you start to understand how many calories are in the foods you eat every day. Over time you begin to learn what foods help you stay lean and what foods can easily push you into eating too many calories. After doing it for a while, you start to know your body better and can make smarter choices without guessing.
Carb cycling is another tool some people use. This means eating more carbohydrates on days when you train hard and eating fewer carbohydrates on days when you rest or are less active. Your body uses carbs as fuel for training, so higher carb days can help with energy and recovery. Lower carb days can help keep calories lower so fat loss can continue.
At the end of the day, calories still matter the most. Carb cycling, food choices, and meal timing can help, but the main thing that controls fat loss or weight gain is whether you are eating fewer calories than you burn, the same amount, or more.