Calculate · beginner · 9 min
How to calculate capital gains tax
Updated 2026-10-12
Educational only. Not tax advice.
- Before you start
- Proceeds minus basis minus selling costs
- Netting short-term and long-term results
- The $3,000 loss limit and what carries over
- The rate that applies after netting
- NIIT and state tax after the federal gain
- The lot you sold
- Missing basis records
- Reinvested dividends and basis
- Stock splits and basis
- Basis of inherited or gifted assets
- Forms that report the sale
Short answer
Sale proceeds minus basis minus selling costs is the gain or loss. A sale of 100 shares at $500, bought at $100, with a $9 selling commission, has proceeds of $49,991 and a gain of $39,991. Net that gain with other gains and losses before you apply a rate.
Key takeaways
- The gain is sale proceeds minus basis minus selling costs, and Card 1 shows proceeds of $49,991 and a gain of $39,991.
- A purchase commission is not a separate calculator field, so a $9 purchase fee on these 100 shares is entered as a buy price of $100.09, which makes the basis $10,009.
- Short-term and long-term results net in four ways, and a $2,000 short-term loss against a $5,000 long-term gain leaves a $3,000 long-term gain.
- A net loss deducts up to $3,000 against ordinary income, or $1,500 if married filing separately, and the rest carries forward with its short-term or long-term character.
- The rate tables live on the 2026 rates guide, and this page keeps the order of the steps.
Before you start
- Sale proceeds
- Sale proceeds are the amount realized on the sale, and in Card 1 they are $49,991 after the $9 selling commission comes off a $50,000 sale.
- Cost basis
- Cost basis starts with what you paid for the shares, and a purchase fee is part of that basis, which is the same split the start-here page uses. This calculator has no purchase-commission field, so you raise the buy price: a $9 purchase commission on these 100 shares is $0.09 a share, the buy price becomes $100.09, and the basis is $10,009. That buy price is not the one in Card 1.
- Adjusted basis
- Adjusted basis is cost basis after later additions such as improvements, and this stock example has no improvement, so adjusted basis equals the $10,000 cost basis.
- Selling costs
- A selling commission reduces proceeds. Closing costs and improvements belong on a home sale, and the [home sale guide](/blog/section-121-home-sale-exclusion/) is the home for those costs. This page does not compute them.
Proceeds minus basis minus selling costs
Proceeds minus basis minus selling costs is the gain when the result is positive, and it is the loss when the result is negative. Card 1 sells 100 shares that were bought at $100 and sold at $500, the $9 selling commission leaves proceeds of $49,991, the basis stays $10,000, and the gain is $39,991.
Federal tax on that gain is $3,081.15, and the net investment income tax is $0. The same sale with no commission is the start-here example, and the $9 selling commission is why this tax is $1.35 lower, which is 15% of $9. The start-here guide is the path from zero, and this page keeps the order of the arithmetic.
Profile A, 100 shares
- Tax year: 2026
- Filing status: Single
- Taxable income before the gain: $30,000
- Shares: 100
- Buy price: $100
- Sell price: $500
- Selling commission: $9
- Buy date: 15 January 2024
- Sell date: 15 June 2026
- Proceeds: $49,991. Basis: $10,000. Gain: $39,991.
- Federal tax on the gain: $3,081.15. NIIT: $0.
- Proceeds before the selling cost: $50,000.00
- Selling cost: $9.00
- Proceeds: $49,991.00
- Basis: $10,000.00
- Gain: $39,991.00
- Federal tax: $3,081.15 (solid mark). NIIT: $0.00.
Source: this calculator, tax year 2026, single filer.
Netting short-term and long-term results
Short-term results are grouped together, long-term results are grouped together, and the two groups meet only when one is a gain and the other is a loss. The grid under this heading is the map, and only one cell is computed: a $2,000 short-term loss against a $5,000 long-term gain leaves a $3,000 long-term gain.
The holding clock that decides which group a sale belongs in lives on the 1-year guide. This page does not re-teach that clock.
| What you have | What happens |
|---|---|
| Short-term gain and long-term gain | Each group stays separate. |
| Short-term loss and long-term loss | Each group stays separate, then the $3,000 limit applies to the net loss. |
| Short-term loss and long-term gain | The loss reduces the long-term gain. Card 2 is this cell. |
| Short-term gain and long-term loss | The loss reduces the short-term gain. |
A short-term loss and a long-term gain
- Tax year: 2026
- Filing status: Single
- Taxable income before the gain: $30,000
- Short-term lot: buy $5,000 on 15 January 2026, sell $3,000 on 15 June 2026. Loss: $2,000.
- Long-term lot: buy $10,000 on 15 January 2024, sell $15,000 on 15 June 2026. Gain: $5,000.
- Net: a $3,000 long-term gain. Federal tax on that gain: $0.
The $3,000 loss limit and what carries over
When the net of every group is a loss, up to $3,000 of that loss deducts against ordinary income, and the cap is $1,500 for married filing separately. The rest carries forward, and a carryover keeps its short-term or long-term character because Schedule D figures those carryovers on separate lines.
Card 3 is one long-term stock loss of $8,000. The deduction this year is $3,000, the carryover is $5,000, and that carryover stays long-term. The loss carryover guide is the home for the next year. This page does not rewrite it.
A net loss above $3,000
- Tax year: 2026
- Filing status: Single
- Shares: 100
- Buy price: $100
- Sell price: $20
- Buy date: 15 January 2024
- Sell date: 15 June 2026
- Loss: $8,000. Deduction this year: $3,000. Carryover: $5,000, and it stays long-term.
The rate that applies after netting
After the groups have netted, a remaining long-term gain is taxed at 0%, 15%, or 20%, and a remaining short-term gain is taxed at ordinary rates from 10% to 37%. The rates guide owns those tables, and this page does not print them.
On Card 2 the net is a $3,000 long-term gain, and federal tax on that gain is $0 for this single filer with $30,000 of taxable income before the gain. Card 1 is the sale that reaches 15%, and its federal tax is $3,081.15.
NIIT and state tax after the federal gain
The net investment income tax is 3.8% when modified adjusted gross income is over $200,000 for single or head of household, $250,000 for married filing jointly, or $125,000 for married filing separately. Card 1 owes $0 of that tax. The NIIT guide is the home for the computation, and this page does not go further than Card 1.
Many states tax a gain even when the federal slice is at 0%. The state overview is the home for those differences, and this page does not paste a state table.
The lot you sold
If you identify the shares you sold, the basis of those shares is the basis you use. If you cannot identify them, Publication 550 says the basis is the basis of the shares you acquired first. Average basis is a choice for mutual fund shares, and it is not the method for these 100 shares of stock.
Missing basis records
If you lost the records that show the basis of a security, the Form 8949 instructions say to contact your broker. Do not invent a basis to fill the gap.
Reinvested dividends and basis
Shares bought with a reinvested dividend have their own basis, so they raise the total basis of the position. Publication 550 sets the basis of shares received through a dividend reinvestment plan at the fair market value on the dividend date.
Stock splits and basis
A stock split divides the same total basis across the new number of shares, so the per-share basis changes and the total does not. Publication 550 shows one share bought for $45 becoming three shares with a basis of $15 each, and the total basis stays $45.
Basis of inherited or gifted assets
Publication 551 says the basis of property inherited from a decedent is generally the fair market value on the date of death. Property you receive as a gift generally carries over the donor’s adjusted basis. When the fair market value at the time of the gift is less than that basis, the basis for figuring a loss is that lower value, and the basis for figuring a gain stays the donor’s basis.
The holding period for those same assets is the gift watch-out on the start-here guide. This page does not add an inherited-basis field to the calculator.
Forms that report the sale
Form 1099-B reports proceeds and, when the broker has it, basis. The instructions for that form tell the broker to reduce proceeds by commissions and transfer taxes related to the sale. If that reduction is already in the proceeds, do not subtract the commission again, because a second subtraction understates the gain. A blank or wrong basis is fixed on the return. The Schedule D guide walks through the forms.
Form 8949 is where an adjustment code explains a difference from the 1099-B. Code W is the nondeductible loss from a wash sale, and code B is the code you enter when the basis shown in box 1e is wrong. A wash sale adds the disallowed loss to the basis of the replacement shares. The wash-sale guide is the home for that rule. This page does not list the other codes and does not fill the form.
Schedule D is where the net of those sales is summarized, including the $3,000 loss limit. This page does not fill it in.
Next, use the rates guide for the tables, the crypto guide for a digital-asset sale, and the home sale guide for a house.
