Why does my Mac use so much swap space?

Solution 1:

When your computer runs out of physical RAM, it swaps some of the data in RAM out to disk.

Later when the need for RAM decreases, you will have a situation where you have free RAM, but still an amount of data swapped out to RAM.

You could argue that the operating system should start swapping that data back into RAM immediately. However there are arguments that this is not a good strategy, namely because:

a) swapping in resources takes away resources from other programs running

b) swapping in resources will occupy RAM that another program might need in a short while, provoking another swap out

These are reasons why the swapped out data isn't immediately swapped in when RAM is freed. Instead it is swapped in when needed.