Shimano publishes the exact procedures to use for determining chain length. There are differences for things like 3x or 2x front. Long, medium or short rear DR and other things. Other mfr's probably publish how they want chains sized to their groupsets too.
Shimano Tech docs are here...
https://si.shimano.com/#/
You need to find the DM's appropriate to your bikes groupset.