One must first establish bmr or basal metoblic rate: the rate we utilise energy at a coma state, then add on for the appropriate level of activity (sedentary or active, even very active) then calculate at 10-20% plussing or minusing this percent according to adding or gaining weight.
But first one needs to establish body fat percentage.
I usually do the equations for myself every few months to see if I'm eating appropriately fory weight, body fat % and activity level.
The math isn't too hard. There are online calculators that do it but I like to know the math myself.