One of the best tax breaks in investing is that no matter how big a paper profit you have on a stock you own, you don't have to pay taxes until you actually sell your shares. Once you do, though, you'll owe capital gains tax, and how much you'll pay depends on a number of factors. Below, you'll learn the key factors in determining how much tax you'll owe after a stock sale.

The basics of capital gains
Under current tax law, you only pay tax on the portion of sales proceeds that represent your profit. To figure that out, you generally take the amount you paid for the stock, and then subtract it from what you received when you sold it. If you had a loss, then not only do you not have to pay tax, but you can also use it as a deduction against other capital gains, and sometimes against other types of income. (Sometimes brokers can help you determine your capital gains -- if you need one, visit our broker center.)

The tax laws also distinguish between long-term capital gains and short-term capital gains. If you've owned a stock for a year or less, then any gain on its sale is treated as short-term capital gain. You'll pay the same tax rate that you pay on other types of income, and so the amount of tax due will vary depending on what tax bracket you're in.

By contrast, if you've held the stock for longer than a year, then you qualify for long-term capital gains treatment. Tax rates for long-term gains are lower than for short-term gains, with those in the 10% and 15% tax brackets paying 0% in long-term capital gains tax, those in the 25% to 35% tax brackets paying 15%, and those in the top 39.6% tax bracket paying 20%.

When things get complicated
A couple of situations often arise to make tax calculation more difficult. First, the cost you use to determine gain or loss can sometimes change. For instance, if you inherit stock, its tax cost is adjusted to reflect its value on the date of death of the person who left it to you. Also, some companies make payments to shareholders that are treated as return of capital, and that adjusts your tax cost downward for purposes of calculating later gain.

The other thing to keep in mind is that there are rules for balancing out gains and losses. First, you add up gains and losses within the short-term and long-term categories across all your stock sales in a given year. Then, a net loss in one category offsets net gains in the other category. Remaining losses can be deducted up to $3,000 against other income, with an excess carried forward to future years.

Selling stock at a profit is always nice, but it comes with a tax hit. Knowing what you'll owe can make you think twice about whether you really want to sell at all.

This article is part of The Motley Fool's Knowledge Center, which was created based on the collected wisdom of a fantastic community of investors. We'd love to hear your questions, thoughts, and opinions on the Knowledge Center in general or this page in particular. Your input will help us help the world invest, better! Email us at knowledgecenter@fool.com. Thanks -- and Fool on!