I am based in the US. Let's say that in 2019 I bought some stocks and sold them in 2019 for a loss of $20k. So in each year starting from 2020, I am able to deduct $3k from my taxable income until all $20k has been deducted.
Let's say that in August 2020 I bought some stocks and sold them in that same month for a capital gain of only $5k. Come year 2021, do I have to pay capital gain taxes on the $5k I made in 2020 or will that $5k be deducted from the $17k capital loss that I am still eligible for, bringing the capital loss to $12k (meaning no capital gain taxes need to be paid in 2021)?