The record-long bull market has given many investors big gains. But that comes with the potential for whopping capital-gains taxes when they sell stocks or funds. Fortunately, because of a higher standard deduction in the new federal tax law, it is easier for many Americans to pay no long-term capital-gains tax at all.

For 2018, you qualify for the 0% rate on all of your long-term capital gains if your taxable income is up to $38,600 for single filers or up to $77,200 for couples filing jointly. If your income exceeds those amounts, you still can take advantage, but you’ll pay a higher tax rate of 15% or 20% on the overage.

Important: Any gains that you realize will be included in your gross income for the year. So if your goal is to maximize use of the 0% long-term gains tax rate, you want to cash out just enough of your investments in a given year to still qualify for it.

Example: A retired married couple receives $45,000 in part-time earnings, $5,000 in interest and $20,000 in pension payments for 2018—a total of $70,000. After taking the standard deduction of $24,000, their taxable income is $46,000. They could realize long-term capital gains of up to $31,200 and qualify for the 0% rate on those gains.

What if you want to continue to hold a particular appreciated stock but take advantage of the 0% rate? You can sell shares to lock in your profits (which results in a realized capital gain on those shares) and then immediately buy back shares in that stock. The IRS “wash rule,” which requires you to wait 30 days to repurchase a security on which you are taking a tax deduction, applies only to investments that you sell at a loss, not at a gain.