The arithmetic, which is a mass balance
Alloying is conservation of gold. Whatever pure gold is present before you add anything is still present afterwards, and the sum works out from that alone. If S grams at fineness s are taken to fineness t by adding A grams of something at fineness a, then S times s plus A times a equals the total mass times t — which rearranges to A equals S times the difference between s and t, divided by the difference between t and a.
A worked case. Ten grams of 24 carat at 999 fine holds 9.99 grams of gold. For that to be 14 carat the total has to be 9.99 divided by 0.585, which is 17.08 grams — so 7.08 grams of alloy goes in. Going the other way, ten grams of 9 carat holds 3.75 grams of gold, and to reach 18 carat you add fifteen grams of fine gold, finishing with 25 grams holding 18.75.
One direction per operation. Adding alloy can only lower the fineness and adding fine gold can only raise it, so a target on the wrong side of your starting metal is not reachable with the addition you have chosen. The tool says which, rather than returning a negative number and leaving you to interpret it.
What the number does not cover
The arithmetic is the easy half. The alloy you add sets the colour and the working properties, and grams say nothing about either — copper pushes gold red, silver and palladium push it pale, zinc lowers the melting point, and nickel makes it white and gives some people a rash. Two alloys of identical fineness can behave completely differently under a torch.
Real melting also loses a little metal to oxide and to the crucible, so treat the figure as the target rather than the yield. And moving down in purity is cheap while moving up is not: sweetening 9 carat to 18 carat means adding one and a half times the original weight in fine gold.