There is a mathematical formula but I don't know what it is and everybody that I know uses the analog approach:
Run your new chain around the biggest chain ring and biggest rear cog bypassing your rear derailleur. Figure out the shortest place that you could rejoin the chain. Now add 1 inch of chain (2 links), including your master link, to that. That's the shortest chain that you can safely use with that gear combination.
__________________
My greatest fear is all of my kids standing around my coffin and talking about "how sensible" dad was.