Selling a winning stock has always had a bitter consequence: paying taxes on your gains. At least, it did until this year.

Tax cuts over the past seven years have reduced the taxes you pay when you sell investments that have risen in value. In 2003, the maximum rate for capital gains fell from 20% to 15%.

The upcoming elections have raised the possibility that those rates could trend higher in the next few years. Yet while attention has focused mainly on the maximum rates, there are even bigger breaks for middle-income taxpayers who decide to sell their stocks this year.

0% rate
Largely hidden within the capital gains rates is a provision that calls for an even lower capital gains rate for those in the first two tax brackets. Because the regular rates in those two brackets are already relatively low -- 10% and 15% -- the reduction in the top capital gains rate wouldn't have had any impact on them. That's why the tax laws gave those folks a special lower rate.

Until this year, that lower rate was 5%. But in 2008, the rate dropped to 0% -- making stock sales tax-free for certain investors. Specifically, if your taxable income is less than $32,550 for singles or $65,100 for married couples filing jointly, then part of your capital gains income may be eligible for the 0% rate.

And here's even more good news: Income from stock dividends is also eligible for the 0% rate.

No taxes? Really?
Here's how it works: The IRS first looks at all your ordinary income, such as your salary and interest on investments. After allowing for adjustments, deductions, and personal exemptions, it then looks at how far you are below the income limits listed above. For any dividends and capital gains up to that amount, you pay nothing in taxes. Any gains or dividends above that amount get taxed at the 15% maximum rate.

So contrary to first appearances, the rule doesn't let you sell millions in stocks at the 0% rate. Once you generate enough income from stock profits to push you out of the bottom two brackets, you'll pay the same higher rate that upper-income taxpayers pay.

But for those with modest incomes, such as seniors who typically get a large portion of their income from Social Security and investment income, the 0% rate opens up a rare tax-planning opportunity, in which it may actually make sense to take gains sooner rather than later.

An example
Say, for instance, you recently retired and have a portfolio of stocks that have gained in value over the years. You and your spouse earn $50,000 per year, of which $10,000 comes from stock dividends. You also have $25,000 of deductions and personal exemptions. You've held the following stocks for the long haul:

Stock

10-Year Average Return

$1,000 Invested in 1998 Now Worth…

Varian Medical (NYSE:VAR)

30.7%

$14,590

Union Pacific (NYSE:UNP)

16.3%

$4,544

Occidental Petroleum (NYSE:OXY)

24.7%

$9,126

Barr Pharmaceuticals (NYSE:BRL)

21.7%

$7,110

QLogic (NASDAQ:QLGC)

17.6%

$5,046

Source: Yahoo! Finance.

Because you're in the first two brackets, that $10,000 from dividends qualifies for the 0% rate. And with net taxable income of $25,000, you could sell all these stocks -- taking more than $35,000 of capital gains -- and still pay nothing in taxes on the gains.

Be careful
Before you take gains, however, be sure to check with your tax advisor to make sure there aren't any other consequences. For instance, if you're receiving Social Security benefits, increasing your overall income may make your benefits taxable, which would increase your tax bill.

In addition, you must hold onto your stocks for more than a year in order to qualify for this lower rate. So if you were fortunate enough to pick up stocks like Myriad Genetics (NASDAQ:MYGN) or Level 3 Communications (NASDAQ:LVLT) at their March lows, and you're looking to take profits, you won't be able to use the 0% rate.

Nevertheless, if you're eligible, the 0% capital gains rate is worth a close look. Although it's slated to continue through 2010, there's no telling what next year will bring. If you can cash in on tax-free gains now, you might want to take advantage before the opportunity disappears.

More on taxes and investments: