The basic formula for stock gains
To find out how much money you made or lost on a stock, subtract what you paid for it from what you sold it for. That is the gain or loss. If you bought 10 shares at $50 each and sold them at $65 each, you paid $500 total and received $650 total — your gain is $150.
The math works the same way whether you made money or lost it. If you bought at $50 and sold at $40, you paid $500 and received $400, so your loss is $100. The formula does not change; only the direction changes.
This simple subtraction is the foundation. Everything else builds from it. But real accounts have complications — you may own different numbers of shares bought at different prices, you may have received dividends, and you may owe taxes on the gain. Those details matter for your actual tax return and your actual wealth, so it is worth learning how to handle them.
Key Takeaways
- Your gain or loss is the sale price minus the purchase price, multiplied by the number of shares you owned.
- If you bought shares at different times and prices, calculate the gain on each batch separately, then add them together.
- Dividends you received count as income and add to your total return, but they are taxed differently than capital gains.
- Your broker's statement shows your cost basis — the total amount you paid — which is the starting number for every calculation.
- Capital gains tax depends on how long you held the stock; the IRS taxes short-term gains (under one year) as ordinary income and long-term gains (one year or more) at lower rates.
Finding your cost basis on your broker statement
Cost basis is the total amount of money you put in. Your broker tracks this automatically and shows it on your account statement. Look for a line that says "cost basis" or "total cost" — it is the number you start with for any calculation.
If you bought 100 shares at $30 per share, your cost basis is $3,000. If you bought 50 shares at $30 and then 50 more at $35, your cost basis is $1,500 plus $1,750, which is $3,250. Your broker does this math for you and displays it on the statement next to each holding.
Some brokers also show your "adjusted cost basis," which accounts for stock splits or special dividends that changed the number of shares you own without you buying or selling. If a company splits its stock two-for-one, your cost basis per share is cut in half, but your total cost basis stays the same. Your broker handles this adjustment automatically.
Calculating gains when you sell all your shares
When you sell every share of a stock you own, the calculation is straightforward. Take the total amount of money you received from the sale, subtract your cost basis, and the result is your gain or loss.
Suppose you bought 50 shares at $40 per share (cost basis: $2,000) and sold all 50 at $55 per share. You received $2,750. Your gain is $2,750 minus $2,000, which is $750. That $750 is your capital gain.
Your broker will send you a form called a 1099-B at tax time that shows the sale price, the cost basis, and the gain or loss. You do not have to calculate it yourself for tax purposes — the form does it for you. But understanding the math helps you know whether the number on the form is correct.
Handling partial sales and multiple purchase dates
If you own 100 shares and sell only 50, or if you bought shares at different times and prices, you need to decide which shares you are selling. The IRS allows several methods, and the method you choose affects your tax bill.
The simplest method is first-in, first-out (FIFO). You assume you sold the shares you bought first. If you bought 50 shares at $30 in January and 50 shares at $40 in June, and you sell 50 shares in December, FIFO assumes you sold the January batch. Your cost basis for those 50 shares is $1,500, and if you sold them at $50 each, you received $2,500, so your gain is $1,000.
Another method is specific identification. You tell your broker exactly which shares you want to sell. If you sell the June batch instead, your cost basis is $2,000, you receive $2,500, and your gain is only $500. This method gives you more control over your tax bill, but you must document which shares you sold and tell your broker before the sale happens.
Your broker defaults to FIFO unless you instruct them otherwise. If you want to use a different method, contact your broker and ask how to set it up. The choice matters most when you have large gains or losses and want to manage your taxes carefully.
Including dividends in your total return
A dividend is a payment a company makes to shareholders, usually in cash. If you owned a stock that paid dividends while you held it, that money counts as part of your return, even though it is separate from your capital gain.
Suppose you bought a stock for $1,000, received $50 in dividends over the time you held it, and sold the stock for $1,100. Your capital gain is $100, but your total return is $150 — the $100 gain plus the $50 in dividends. Both are income, but the IRS taxes them differently. Dividends are taxed as ordinary income or as may have access to dividends (at lower rates), depending on how long you held the stock and the type of dividend.
Your broker reports dividends on a separate form called a 1099-DIV. You do not add dividends to your capital gain on your tax return; you report them in a different section. But for your own understanding of how much money the investment made, adding dividends to your capital gain shows your true return.
Understanding short-term versus long-term gains
The IRS taxes capital gains differently depending on how long you held the stock. If you held it for one year or less, it is a short-term capital gain, taxed as ordinary income at your regular tax rate. If you held it for more than one year, it is a long-term capital gain, taxed at a lower rate.
The holding period starts the day after you buy and ends the day you sell. If you bought on January 15 and sold on January 16 of the next year, you held it for more than one year, so it qualifies as long-term. If you sold on January 15 of the next year, it is short-term.
Long-term capital gains rates are 0%, 15%, or 20%, depending on your income. Short-term gains are taxed at your ordinary income tax rate, which can be as high as 37%. This difference is why many investors think about the timing of their sales — holding a stock just a few more weeks or months can significantly reduce the tax you owe on the gain.
Accounting for fees and commissions
Some brokers charge a commission when you buy or sell a stock. If you pay a commission, it reduces your gain or increases your loss. Add any commission you paid to your cost basis, and subtract any commission you paid when you sold from the sale price.
If you bought 100 shares at $50 per share and paid a $10 commission, your cost basis is $5,010, not $5,000. If you sold those 100 shares at $55 per share and paid a $10 commission, you received $5,500 minus $10, which is $5,490. Your gain is $5,490 minus $5,010, which is $480.
Most major brokers no longer charge commissions on stock trades, so this matters less than it once did. But if you use a broker that does charge, or if you trade through a financial advisor who takes a fee, those costs are part of your true return and belong in the calculation.
Frequently Asked Questions
Do I have to report gains if I did not sell the stock?
No. The IRS only taxes capital gains when you sell. If you own a stock that has gone up in value but you still hold it, you owe no tax on that gain yet. The gain is "unrealized" until you sell. Once you sell, the gain becomes "realized" and is taxable.
What if I sold a stock at a loss?
A loss reduces your taxable income. You can use capital losses to offset capital gains, and if your losses exceed your gains, you can deduct up to $3,000 of the loss against ordinary income in a single year. Any loss beyond that carries forward to future years. Keep records of all losses so you can report them correctly.
How do I know what my cost basis is if I inherited stock?
Inherited stock gets a "stepped-up basis," meaning your cost basis is the stock's value on the date the person died, not what they paid for it. Your broker should have this information, but if not, you may need to contact the estate or use the stock's price on that date from a financial website.
Can I change my mind about which shares I sold?
No, once you sell, the transaction is final. But you can use specific identification on your next sale to choose which shares to sell then. If you made a mistake on a past return, you can file an amended return to correct it, but you cannot change the actual sale that already happened.
What if I bought and sold the same stock multiple times in one year?
Each buy-and-sell pair is a separate transaction. Calculate the gain or loss for each one separately. If you bought at $40, sold at $50, bought again at $45, and sold at $55, you have two gains: $10 on the first pair and $10 on the second. Both are short-term if you held each for under one year, and both are taxable in the year you sold.