The arithmetic of a stock sale is simple and easy to get slightly wrong — usually by forgetting commissions, or by miscounting the holding period around the one-year line.
General rule only. Long-term means held more than one year. Wash-sale disallowance, inherited or gifted lots, and specific-lot vs average-cost accounting all change the result. Not tax advice.
How the numbers work
Cost basis is the total you paid to acquire the shares: shares times purchase price, plus the commission on the buy. Commissions increase your basis, which reduces your taxable gain.
Proceeds are what you received: shares times sale price, minus the commission on the sell.
Gain or loss is proceeds minus basis. A positive number is a capital gain; a negative one is a capital loss, which can offset other gains and, up to a limit, ordinary income.
Holding period decides the tax rate. One year or less from purchase is short-term, taxed as ordinary income. More than one year is long-term, taxed at the lower capital-gains rates. The clock starts the day after you buy and runs through the sale date, so a purchase on 1 February one year and a sale on 2 February the next is long-term by a day.
What this does not cover
- Wash sales. Realising a loss and rebuying substantially identical shares within 30 days (either side) disallows the loss for now and rolls it into the basis of the new shares.
- Multiple lots. If you accumulated a position over time, each purchase is its own lot with its own basis and holding period. Which lots you are deemed to sell (FIFO, specific identification, average cost for funds) changes the result.
- Inherited and gifted shares. Inherited shares generally get a stepped-up basis to the value at the date of death; gifted shares usually carry the donor's basis.
- State tax, the net investment income tax, and anything specific to your situation.
This is a general-case calculator, not tax advice. For anything with lots, losses near the 30-day boundary, or an inheritance, check with a tax professional.
The short version
Basis is price paid plus buy commission; proceeds are price received minus sell commission; gain is the difference. Hold more than a year — not exactly a year — for the long-term rate. Wash sales, multiple lots and inherited shares each break the simple formula.
Related: how to read a Form 4, field by field · the Section 16 deadline calculator · is insider buying a bullish signal?