Get your taxes done using TurboTax

You can use $3,000 of your $20,000 carryforward loss to offset your 2021 $3,000 gain. Then you can use another $3,000 of your $20,000 loss to offset all of your other income (which would leave a $14,000 carryforward to 2022).