Under the wash-sale rules, if you sell stock for a loss and buy it back within the 30-day period before or after the loss-sale date, the loss cannot be immediately claimed for tax purposes.
The wash sale rule only applies to losses. You can't wipe out a gain from a sale by buying the same stock back within 30 days.
You pay tax on the entire gain.
I sincerely XXXXX XXXXX information is helpful,