It's no secret that the capital gains tax can hit investors hard. If the value of your stocks went up between when you bought and when you sold them, you'll probably owe the government a chunk of your earnings.

But for some Americans -- in fact, far more than you probably think -- there's a way to sell your stocks and not owe the government a penny in taxes.

Of course, as with all things in our tax code, there are a number of restrictions. But for the average U.S. family, avoiding the capital gains tax altogether could provide huge long-term benefits.

Three tile letters spelling TAX on top of a calculator

Image source: Getty Images.

But first ...
One housekeeping item to get out of the way first: For this article, I'm talking strictly about the capital gains tax from selling stocks. You can also pay this tax on other holdings, like collectibles and precious metals, but we'll ignore that for now.

The first step in eliminating the capital gains tax
If you want to avoid the taxman, you must hold shares of a company for more than a year. This qualifies your investment gains as "long-term" as opposed to "short-term." But since we're long-term investors here at The Motley Fool -- meaning we invest with a minimum three-year time horizon -- that shouldn't be too difficult.

If, however, you get a little impatient and sell shares before a year passes, you'll end up paying the same amount as your normal tax rate on any gains. What do those rates look like? Here's what they are for 2014:

Income thresholds

Tax Bracket

Single

Married, Filing Jointly or Qualified Widow(er)

Married, Filing Separately

Head of Household

10%

 $9,075

 $18,150

 $9,075

 $12,950

15%

 $36,000

 $73,800

 $36,900

 $49,400

25%

 $89,350

 $148,850

 $74,425

 $127,550

28%

 $186,350

 $226,850

 $113,425

 $206,600

33%

 $405,100

 $405,100

 $202,550

 $405,100

35%

 $406,750

 $457,600

 $228,800

 $432,200

39.60%

 over $406,750

 over $457,600

 over $228,800

 over $432,200

Source: IRS.

It's important to remember that any proceeds you get from selling stocks will go toward your taxable income as well. In other words, if you are single and earned $89,350 in taxable income before selling any stocks, you would pay 28% in short-term capital gains taxes, because you bumped up a bracket.

The second requirement to avoid the capital gains tax
In short: Stop earning too much! That may sound counterproductive, but if you fall in one of the first two tax brackets for your given status, you will owe exactly nothing to the government when you sell shares and make a profit.

Here's what the tax schedule looks like for long-term capital gains:

Tax Bracket

Long-Term Capital Gains Tax

10%

0%

15%

0%

25%

15%

28%

15%

33%

15%

35%

15%

39.6%

20%

Source: IRS.

But there's a catch -- and it's a good one
Of course you might look at this and say: "Well that doesn't help me! My family brings in more than $73,800." While it may be true that there's no way to avoid paying this tax for some, it's important to remember that the dollar amounts in the first chart represent your taxable, not gross, income.

In other words, let's consider the stereotypical American household: married couple and two school-aged kids. This family will bring home $92,000 in 2014. Because of standard deductions and personal exemptions, they could sell stocks and produce $10,000 in gains and pay absolutely no tax on those gains.

Here's why that works:

Gross Income

$92,000

Standard Deduction

($12,400)

Personal Exemptions ($3,950 each)

($15,800)

Taxable Income

$63,800

In the end, one could argue that these exceptions don't really matter, as the average middle-income family doesn't hold many stocks in non-retirement accounts anyway. While that may be true for most, we Fools believe that long-term investing in the stock market is the best way to build wealth, no matter your income level. And as it is, the family described here would be in the top quarter of household incomes in America.

While you'll have to do your own homework to figure out if you could avoid the capital gains tax at year's end, the message is clear: For the majority of Americans, there's some benefit to at least investigating how to avoid paying the capital gains tax altogether.