The worked example
Book a 60000 loss. The 20000 bill becomes 8000.
A short term loss cancels both short and long term gains. A long term loss cancels only long term gains. Point the loss at the highest rate you have.
The rule under it
A booked loss is worth its size times the tax rate on the gain it cancels.