To calculate gain or loss on stock for taxes, subtract your adjusted cost basis from your net sale proceeds: a positive number is a capital gain, a negative number is a capital loss. How long you held the shares before selling then decides whether the result is taxed at ordinary income rates (short-term) or the lower long-term capital gains rates. Losses beyond what you can use this year carry forward with no expiration.
The Two Numbers You Need
Every calculation starts with what you paid and what you received. Your brokerage reports both on Form 1099-B, which it sends to you and the IRS after each tax year.1Internal Revenue Service. About Form 1099-B, Proceeds from Broker and Barter Exchange Transactions
Cost basis is the total amount you paid for the shares, including the purchase price plus any transaction fees or commissions.2Internal Revenue Service. Publication 551, Basis of Assets Buy 100 shares at $50 with a $10 commission and your basis is $5,010. Most brokerages have dropped commissions on stock trades, but older lots may still carry them, and the fee belongs in basis when it exists.
Proceeds are the sale price minus any fees on the sell side. Selling those same shares for $7,000 with a $15 fee gives net proceeds of $6,985. Statements sometimes list gross proceeds with fees shown separately, so check whether the 1099-B figure is already net.
The math is subtraction. Bought 50 shares for a $2,000 total basis, sold them for $2,800 after fees: an $800 gain. Sold them instead for $1,600 after fees: a $400 loss. You run this for every lot sold during the year.
Basis When You Didn’t Buy the Shares
Inherited stock gets a stepped-up basis equal to the fair market value on the date the original owner died, regardless of what they originally paid.2Internal Revenue Service. Publication 551, Basis of Assets If a parent paid $5,000 thirty years ago and the stock was worth $80,000 at death, your basis is $80,000. Selling for $82,000 produces only a $2,000 gain. Inherited stock is also automatically treated as long-term no matter how quickly you sell it.
Gifted stock trips people up because you generally inherit the donor’s original basis. If the donor paid $3,000 and hands you shares worth $15,000, your basis is $3,000. Sell for $15,000 and you owe tax on a $12,000 gain even though none of that appreciation happened in your account.3Internal Revenue Service. Property (Basis, Sale of Home, etc.) A special dual-basis rule applies when the stock’s value on the gift date is below the donor’s basis; if a later sale price falls between those two figures, you have neither gain nor loss. You also get credit for the donor’s holding period when using the donor’s basis.
Which Shares Are You Selling?
If you bought the same stock at different times and prices, your basis depends on which lot you’re treated as selling. The IRS default is first-in, first-out: the earliest shares are sold first.4Internal Revenue Service. Stocks (Options, Splits, Traders) FIFO usually means selling your lowest-cost shares first, which produces the largest taxable gain.
You can override FIFO with specific identification, telling your broker exactly which lots to sell before the trade settles. This lets you pick higher-cost shares to shrink a gain, or lots with a longer holding period to qualify for long-term rates. The identification has to happen at the time of the sale, and you need written confirmation from your broker.5Internal Revenue Service. Publication 550, Investment Income and Expenses Most online platforms let you select specific lots when placing a sell order, which meets both requirements.
Adjustments That Change Your Basis
Original purchase price isn’t always your final basis. Stock splits redistribute it: in a 2-for-1 split, your share count doubles and your per-share basis is cut in half, while total basis stays the same. Reverse splits work the other way.
Mergers and acquisitions can force you to allocate original basis across new shares in the acquiring company, sometimes mixed with cash. The brokerage should provide the allocation, but these are worth checking because an error compounds through every later sale.
Dividend reinvestment creates its own complication. Each reinvested dividend buys additional shares, and each purchase is a new lot with its own basis and holding period. After a few years, one holding may contain dozens of lots. Forgetting to include reinvested-dividend shares in your total basis is a common mistake that inflates the reported gain and leads to overpaying.
How Long You Held the Shares
Holding period decides the tax rate. One year or less is short-term; more than one year is long-term.6Internal Revenue Service. Topic No. 409, Capital Gains and Losses The count starts the day after you buy and runs through the day you sell. Buy on March 15, 2025, and you’d need to sell on or after March 16, 2026 to clear the one-year mark. A single day short and the gain is short-term, which can raise the bill significantly.
The Rate That Applies to Your Result
Short-term gains are taxed at ordinary income rates, which for 2026 range from 10% to 37% depending on taxable income and filing status.7Internal Revenue Service. IRS Releases Tax Inflation Adjustments for Tax Year 2026 A short-term gain stacks on top of your other income and gets taxed at whatever bracket it lands in.
Long-term gains get preferential federal rates of 0%, 15%, or 20% for 2026, based on taxable income:8Internal Revenue Service. Revenue Procedure 2025-32, 2026 Adjusted Items
- 0% up to $49,450 (single) or $98,900 (married filing jointly)
- 15% above the 0% threshold up to $545,500 (single) or $613,700 (married filing jointly)
- 20% above $545,500 (single) or $613,700 (married filing jointly)
Higher earners also owe a 3.8% net investment income tax on capital gains once modified adjusted gross income exceeds $200,000 (single) or $250,000 (married filing jointly).9Internal Revenue Service. Topic No. 559, Net Investment Income Tax That pushes the top effective long-term rate to 23.8%. Most states tax capital gains as well, from 0% in states with no income tax up to roughly 13% or more, so the combined bite can be considerably larger than the federal number alone.
The Wash Sale Rule Can Erase a Loss
Selling a stock at a loss and buying it back too soon triggers the wash sale rule. If you buy substantially identical stock within 30 days before or 30 days after the sale, the IRS disallows the loss.10Office of the Law Revision Counsel. 26 USC 1091 – Loss from Wash Sales of Stock or Securities The window runs in both directions, creating a 61-day period around the sale during which a repurchase disqualifies the loss.
The disallowed loss isn’t lost forever. It gets added to the basis of the replacement shares, deferring the tax benefit until you sell those replacement shares without triggering another wash sale.11Internal Revenue Service. Case Study 1 – Wash Sales Sell for a $500 loss, repurchase for $2,000, and your new basis is $2,500. Your broker typically flags a wash sale in Box 1g of Form 1099-B, but tracking gets harder when trades span multiple accounts.
The rule also applies across account types. Buy the same stock in your IRA within 30 days of selling it at a loss in a taxable account and the loss is disallowed, with the adjustment landing on IRA shares where it provides no future tax benefit.
If the Stock Became Worthless
When a stock becomes completely worthless, you can still claim a capital loss. The IRS treats worthless securities as if sold on the last day of the tax year in which they became worthless.12Office of the Law Revision Counsel. 26 US Code 165 – Losses Your loss equals your full cost basis, and because the deemed sale date is December 31, the holding period almost always makes it long-term. A stock still trading at a fraction of a penny isn’t technically worthless yet, so the harder part is pinning down the correct year.
Reporting the Number to the IRS
Two forms carry the calculation onto your return. Form 8949 lists each transaction: purchase date, sale date, proceeds, cost basis, and gain or loss. Part I is short-term, Part II is long-term.13Internal Revenue Service. Instructions for Form 8949 If your 1099-B shows that basis was reported to the IRS and no adjustments are needed, you can skip Form 8949 for those transactions and enter the totals directly on Schedule D.
Schedule D takes the totals from Form 8949, combines short- and long-term results, and produces your net capital gain or loss, which flows to your Form 1040.14Internal Revenue Service. About Form 8949, Sales and Other Dispositions of Capital Assets
If total losses exceed total gains, you can deduct up to $3,000 of the net loss against ordinary income ($1,500 if married filing separately). Anything beyond that carries forward with no expiration and can offset gains in future years.6Internal Revenue Service. Topic No. 409, Capital Gains and Losses Keep your Schedule D worksheets and Form 8949 records so you can track the carryforward accurately on future returns, and hold onto basis records generally, because the IRS can ask you to prove your numbers years after a sale.