If you sell stock for more than you originally paid for it, then you may have to pay taxes on your profits, which are considered a form of income in the eyes of the IRS (bummer!).

Specifically, profits resulting from the sale of stock are a type of income known as capital gains, which have unique tax implications. Here's what you need to know about selling stock and the taxes you may have to pay.

## How to calculate your profits from selling stocks

When you sell stock, you're responsible for paying taxes only on the profits -- not on the entire sale.

In order to determine your profits, you need to subtract your cost basis (also known as your tax basis), which consists of the amount you paid to buy the stock in the first place plus any commissions or fees you paid to buy and sell the shares.

### Example

Let's say you bought 10 shares of stock in Company X for \$10 apiece and paid \$5 in transaction fees for the purchase. If you later sold all the stock for \$150 total, paying another \$5 in transaction fees for the sale, here's how you'd calculate your profits:

Cost basis = \$100 (10 shares @ \$10 each) + \$10 (purchase and sale fees @ \$5 each) = \$110

Profits = \$150-\$110 = \$40.

So in this example you'd pay taxes on the \$40 in profits, not the entire \$150 total sale price.

Now that you've determined your profits, you can calculate the tax you'll have to pay, which depends on your total income for the year and the length of time you held the shares.

Image source: Getty Images.

## How do taxes work on stocks?

Generally speaking, if you held your shares for one year or less, then profits from the sale will be taxed as short-term capital gains. If you held your shares for longer than one year before selling them, the profits will be taxed at the lower long-term capital gains rate.

Both short-term and long-term capital gains tax rates are determined by your overall taxable income. Your short-term capital gains are taxed at the same rate as your marginal tax rate (tax bracket). You can get an idea of what your tax bracket might be from the IRS for 2020 or 2021.

For the 2020 tax year (i.e., the taxes most individuals will file by April 2021), long-term capital gains rates are either 0%, 15%, or 20%. Unlike in past years, the break points for these levels don't correspond exactly to the breaks between tax brackets:

Long-Term Capital Gains Tax Rate

Single Filers (Taxable Income)

Married Filing Jointly/ Qualifying Surviving Spouse

Married Filing Separately

0%

Up to \$40,000

Up to \$80,000

Up to \$53,600

Up to \$40,000

15%

\$40,001-\$441,450

\$80,001-\$496,600

\$53,601-\$469,050

\$40,001-\$248,300

20%

Over \$441,450

Over \$496,600

Over \$469,050

Over \$248,300

Data source: Internal Revenue Service Revenue Procedure document 2019-44. Figures represent taxable income, not just taxable capital gains.

Looking ahead to the 2021 tax year (i.e., the taxes most individuals will file by April 2022), the three long-term capital gains rates of 0%, 15%, and 20% remain the same, but the brackets are adjusted slightly upward for inflation:

Long-Term Capital Gains Tax Rate

Single Filers (Taxable Income)

Married Filing Jointly/ Qualifying Widow(er)

Married Filing Separately

0%

Up to \$40,400

Up to \$80,800

Up to \$54,100

Up to \$40,400

15%

\$40,401-\$445,850

\$80,801-\$501,600

\$54,101-\$473,750

\$40,401-\$250,800

20%

Over \$445,850

Over \$501,600

Over \$473,750

Over \$250,800

Data source: Internal Revenue Service Revenue Procedure document 2020-45. Figures represent taxable income, not just taxable capital gains.

To calculate your tax liability for selling stock, first determine your profit. If you held the stock for less than a year, multiply by your marginal tax rate. If you held it for more than a year, multiply by the capital gain rate percentage in the table above.

But what if the profits from your long-term stock sales push your income to a higher bracket? This is sometimes known as the "bump zone." Since capital gains rates are marginal, like ordinary income tax rates, you'd pay the higher rate only on the capital gains that caused your income to exceed the threshold. Remember that capital gains are not limited only to stock sales, but any sales of investment assets, including real estate.

### Example

Let's say you make \$50,000 of ordinary taxable income in 2020 and you sell \$100,000 worth of stock profit that you've held for more than a year. You'll pay taxes on your ordinary income first, then pay a 0% capital gains rate on the first \$28,750 in gains, because that portion of your total income is below \$78,750. The remaining \$71,250 of gains are taxed at the 15% tax rate.

## How to avoid paying taxes when you sell stock

One way to avoid paying taxes on stock sales is to sell your shares at a loss. While losing money certainly isn't ideal, at least losses you incur from selling stocks can be used to offset any profits you made from selling other stocks during the year. And if your total capital losses exceed your total capital gains for the year, you can deduct up to \$3,000 of those losses against your total income for the year.

I know what you're thinking: No, you can't sell a bunch of shares at a loss to lower your tax bill and then turn around and buy them right back again. The IRS doesn't allow this kind of "wash sale" -- so called because the net effect on your assets is "a wash" -- to reduce your tax liability. If you repurchase the same or "substantially similar" stocks within 30 days of the initial sale, it counts as a "wash sale" and can't be deducted.

Of course, if you end the year in the 0% long-term capital gains bracket, you'll owe the government nothing on your stock sales. The only other way to avoid tax liability when you sell stock is to buy stocks in a tax-advantaged account.

## What is a tax-advantaged stock account?

A tax-advantaged account is an investment account like a 401(k), 403(b), or traditional IRA. In these accounts your contributions may be tax-deductible, but your qualified withdrawals will typically count as income. Roth accounts, on the other hand, are tax-free investment accounts: You can't get a tax deduction for contributing, but none of your qualified withdrawals will count as taxable income.

With any of these accounts, you will not be responsible for paying tax on capital gains -- or dividends, for that matter -- so long as you keep the money in the account. The drawback is that these are retirement accounts, so you are generally expected to leave your money alone until you turn 59 1/2 years old.