Calculating Stock Gains and Losses: A Step-by-Step Guide
By Markets & Investing DeskUpdated Nov 10, 2026
Key takeaways
- Percentage gain or loss equals the sale price minus the purchase price, divided by the purchase price, times 100.
- A gain stays unrealized while you hold the shares and becomes a realized, taxable capital gain only when you sell.
- Two trades that each earn $700 can return 70% or 7%, depending on how much capital each one required.
- Recovering from a loss takes a larger gain: a 20% drop needs 25% to break even, and a 50% drop needs 100%.
To calculate profit and loss on a stock, subtract what you paid for the position from what you got (or would get) for it, then divide by what you paid to express the result as a percentage. In dollar terms, P&L = (sale price × shares) − (purchase price × shares) − fees. In percentage terms, % gain or loss = (sale price − purchase price) ÷ purchase price × 100. That gives the gross result. Your net result, the money you actually keep, also accounts for dividends received, commissions and other costs, margin interest if you borrowed, and taxes once you sell.
Realized vs. Unrealized Gains and Losses
A gain is an increase in an asset’s market value above what you paid for it. A loss is a decrease below that price. As long as you still own the shares, the gain or loss is unrealized, sometimes called a paper gain or loss. It can grow, shrink or reverse with every move in the stock price.
When you sell, the result becomes realized: an actual capital gain or capital loss, and the moment it becomes relevant for taxes. A brokerage account showing a position up $2,000 is showing an unrealized, gross figure that usually does not subtract the tax you would owe if you sold today.
The Basic Formulas
Two calculations answer two different questions.
Dollar profit or loss answers “how much money?”
Dollar P&L = (Sale price × Number of shares) − (Purchase price × Number of shares) − Fees
Percentage gain or loss answers “how much relative to what I put in?”
% Change = [(Sale price − Purchase price) ÷ Purchase price] × 100
For a position you still hold, replace the sale price with the current market price. The result is your unrealized P&L.
A positive result is a gain; a negative result is a loss. If you have the total cost and total value rather than per-share prices, the same formula works with totals: (current value − total cost) ÷ total cost × 100.
Step-by-Step Example
Suppose you buy 100 shares at $122 and later sell them at $150, paying a $5 commission on each trade (hypothetical figures).
- Total cost: 100 × $122 = $12,200, plus the $5 buy commission = $12,205.
- Sale proceeds: 100 × $150 = $15,000, minus the $5 sell commission = $14,995.
- Dollar gain: $14,995 − $12,205 = $2,790.
- Percentage gain: $2,790 ÷ $12,205 × 100 = about 22.9%.
Without fees, the move from $122 to $150 is ($150 − $122) ÷ $122 × 100 = 22.95%. The commissions shave the return only slightly here because the position is large relative to the fees. On a $200 position, the same $10 in round-trip commissions would cost 5 percentage points of return.
If the shares had instead fallen to $100, the gross result would be ($100 − $122) ÷ $122 × 100 = −18.0%, a loss of $2,200 before fees.
Scaling From One Share to a Position
The per-share result scales with the number of shares. If one share costs $350, 100 shares cost $35,000, and a $10 move per share becomes a $1,000 move in the position. The percentage stays the same whether you own one share or 1,000: a stock that rises from $350 to $385 gains 10% for every holder, regardless of position size.
The same arithmetic works in reverse for fractional shares. If you paid $24.42 for 0.012 of a share, the price per share was $24.42 ÷ 0.012 = $2,035.
Why Percentages Beat Dollar Amounts
A dollar figure on its own says nothing about efficiency. Consider two hypothetical trades:
- Stock A: You buy 100 shares at $10 ($1,000) and sell at $17 ($1,700). Profit: $700. Return: ($17 − $10) ÷ $10 = 70%.
- Stock B: You buy 1,000 shares at $10 ($10,000) and sell at $10.70 ($10,700). Profit: $700. Return: ($10.70 − $10) ÷ $10 = 7%.
Both trades made $700. Stock A did it with one-tenth of the capital, so it earned ten times the return. If you had put the $10,000 into Stock A instead, the same 70% move would have produced $7,000.
Percentages also let you compare a stock with a benchmark such as the S&P 500, or with a savings rate, over the same period. Over long periods, comparing with the inflation rate shows whether the gain increased your purchasing power or only kept pace with rising prices.
Total Return: What the Simple Formula Leaves Out
The purchase-to-sale difference is the gross, or nominal, return. A fuller formula adds income and subtracts every cost:
Total return = [(Sale price − Purchase price) + Dividends − Commissions − Account fees − Margin interest − Taxes] ÷ Initial investment × 100
Each component deserves its own look, because each can change the answer.
Dividends
Dividends paid while you hold the stock are part of your return even if the share price never moves. A stock bought at $50, sold at $50, that paid $2 in dividends along the way returned 4%, not 0%.
Total return with dividends = [(Final price − Initial price) + Dividends] ÷ Initial price × 100
You can take dividends as cash or reinvest them to buy more shares. Reinvested dividends buy new shares at the price on each payment date, which adds new lots to your position and raises your cost basis (covered below). Cash dividends are generally taxable in the year received in a taxable account, whether or not you sell the stock.
Commissions and Fees
Many U.S. brokers no longer charge commissions on most stock and ETF trades, but fees have not disappeared everywhere. Costs that can still reduce your net result include:
- Per-trade fees: a flat amount or a percentage of the trade’s value, still charged by some brokers and on some products such as options or certain mutual funds.
- Account, platform or data fees: maintenance charges or subscriptions for premium tools.
- Spreads and currency conversion: the gap between the bid and ask price, and conversion costs when you buy a foreign stock in another currency.
A commission applies on both the purchase and the sale, so a $5 fee per trade is $10 round trip.
Margin Interest and Leverage
Trading on margin means borrowing from your broker to buy more stock than your cash alone would allow. Leverage magnifies the percentage result on your own money in both directions, and the loan carries interest that reduces your return.
To estimate the interest cost:
Margin interest = Margin balance × Annual interest rate × (Days borrowed ÷ 365)
Assumption: simple interest at a constant rate. Brokers typically calculate margin interest daily and may change rates, so the actual figure can differ. As a hypothetical example, borrowing $5,000 at 10% for 73 days costs $5,000 × 0.10 × (73 ÷ 365) = $100. Subtract that from the gross dollar gain before computing your return.
Leverage changes which base you divide by. Suppose you put up $50 and control a $250 position (5× leverage, hypothetical). If the stock rises 5%, the position gains $12.50, which is 25% of your $50. If it falls 5%, you lose $12.50, also 25% of your money, before interest and fees. A 20% drop in the stock would wipe out the entire $50. When the value of a margined position falls far enough, the broker can issue a margin call and, if you do not add funds, sell your shares, which locks in the loss at the worst point.
Taxes
In the U.S., capital gains are taxed when realized, and the rate depends on how long you held the shares:
- Short-term (held one year or less): taxed at your ordinary income tax rate.
- Long-term (held more than one year): taxed at preferential rates of 0%, 15% or 20%, depending on your taxable income and filing status.
The holding period runs from the day after you buy to the day you sell. To find your after-tax gain, multiply the taxable gain by your applicable rate and subtract the result. Under a hypothetical 15% rate, a $2,790 long-term gain leaves $2,790 × (1 − 0.15) = $2,371.50. A flat rate works the same way: under a 10% tax on profit, profit × 0.90 remains.
Losses have value too. Realized capital losses offset realized capital gains. If losses exceed gains, up to $3,000 of the net loss ($1,500 if married filing separately) can offset ordinary income each year, with the rest carried forward. Deliberately selling losing positions to offset gains is called tax-loss harvesting.
The wash sale rule limits that strategy. If you buy a substantially identical security within 30 days before or after selling at a loss, you cannot claim the loss at that time. The disallowed loss is added to the cost basis of the replacement shares, which defers the tax benefit rather than eliminating it.
Other cases follow different rules. Options and other derivatives can be taxed differently from ordinary shares, foreign holdings such as ADRs may involve foreign withholding tax and potential foreign tax credits, and gains inside tax-advantaged retirement accounts are generally not taxed at the time of the sale. Rules outside the U.S. differ by country.
Cost Basis: The Number Your Gain Is Measured From
Your cost basis is the original value of your investment for tax purposes: the purchase price plus associated costs such as commissions. If you bought stock for $1,000 and paid $10 in fees, your basis is $1,010. Your taxable gain or loss is the sale proceeds (after selling costs) minus that basis.
Getting the basis right matters in both directions. Report a basis that is too low and you overstate your gain and overpay tax. Brokers now track and report cost basis for many securities, but the figure still depends on events that change it over time.
Buying More Shares: Average Cost
When you add to a position at a different price, your overall P&L depends on your average cost per share:
Average cost = Total amount paid for all shares ÷ Total shares
For example, buying 6,040 shares at $15.25 ($92,110) and 2,800 shares at $13.00 ($36,400) gives a total cost of $128,510 for 8,840 shares. The average cost is $128,510 ÷ 8,840 = about $14.54 per share. At a current price of $16, your unrealized gain is ($16 − $14.54) × 8,840, roughly $12,900, or about 10% on cost.
This is how a P&L percentage based on average price works: (current price − average price) ÷ average price × 100. Buying more shares below your average lowers it; buying above raises it. The position’s total gain or loss is the same either way you compute it, because it rests on total cost and total value.
Which Shares Did You Sell?
For taxes, a partial sale is not always measured against the average. Each purchase is a separate lot with its own price and date. In the U.S., if you do not specify which shares you are selling, the default for stocks is generally first in, first out (FIFO): the oldest shares are treated as sold first. Many brokers let you choose specific identification instead, picking the lots with the highest basis to reduce a gain or lots held over a year to qualify for long-term rates. Average cost is permitted for mutual fund shares and certain dividend reinvestment plans.
The method affects both the size of your reported gain and whether it is short-term or long-term, so the same sale can produce different tax results depending on the lots chosen.
Splits, Reinvested Dividends and Other Adjustments
- Stock splits change the number of shares and the per-share basis but not the total basis. After a 2-for-1 split, 100 shares with a $40 basis become 200 shares with a $20 basis, still $4,000 in total.
- Reinvested dividends each create a new lot at that day’s price, adding to the total basis. Forgetting them leads to double taxation: once on the dividend and again as part of an overstated gain.
- Return of capital distributions reduce your basis rather than counting as income.
- Inherited shares in the U.S. generally take a basis equal to their fair market value on the date of the owner’s death (the stepped-up basis). Gifted shares generally carry over the giver’s basis.
When Percentages Don’t Add Up
Because each percentage change is measured from a new starting value, percentages compound rather than add.
Consecutive moves. If a stock rises 25% and then falls 20%, the total change is not +5%. Starting at $100, a 25% rise takes it to $125, and a 20% fall from $125 takes it to $100. The net change is 0%. The general formula is:
Total change = (1 + first change) × (1 + second change) − 1
Here: 1.25 × 0.80 − 1 = 0.
Recovering from a loss. The gain needed to get back to even is larger than the loss that put you there:
Required gain = Loss ÷ (1 − Loss)
A 20% loss needs a 25% gain to recover. A 50% loss needs 100%. A 75% loss needs 300%. To find the price needed to regain your value, divide your cost basis by the current price and subtract 1. If you paid $40 and the stock is at $30, it needs to rise ($40 ÷ $30) − 1 = 33.3%.
Very large gains. A 5,000% gain means the investment is worth 51 times its cost (the original amount plus 50 times it). On $1,000, that is $51,000 in value and a $50,000 gain before taxes.
Comparing Returns Over Different Time Periods
A 30% gain over six months and a 30% gain over five years are very different results. To compare them, convert to an annualized return (compound annual growth rate):
Annualized return = (Ending value ÷ Beginning value)^(1 ÷ Years) − 1
Assumption: one starting investment, no additions or withdrawals, with dividends included in the ending value if they were reinvested. For example, $1,000 growing to $1,500 over three years is (1.5)^(1/3) − 1 = about 14.5% per year, not 50% ÷ 3 = 16.7%. The simple division overstates the yearly rate because it ignores compounding. If you added money along the way, a money-weighted calculation (such as the XIRR function in a spreadsheet) gives a more accurate figure.
Setting Up a Spreadsheet Calculation
A spreadsheet in Excel or Google Sheets can act as your own stock profit calculator, and it scales to every position you hold.
- In row 1, label the columns: A1 Shares, B1 Purchase Price, C1 Current or Sale Price, D1 Fees, E1 Dollar P&L, F1 % Change.
- Enter one position per row starting in row 2.
- In E2, enter
=A2*(C2-B2)-D2for the dollar gain or loss after fees. - In F2, enter
=E2/(A2*B2+D2)*100for the percentage return on everything you paid. For the price change alone, use=(C2-B2)/B2*100. - Drag the formulas down to fill additional rows.
For the hypothetical Stock A trade above (100 shares, $10 to $17, no fees), E2 shows $700 and F2 shows 70%. Give each lot of the same stock its own row, then sum the dollar column and divide by total cost for the combined percentage. Columns for dividends and purchase dates add total return and long-term status.
FAQs
How do I calculate my overall P&L across a whole portfolio?
Add up the current value of every position and subtract the total cost basis of all of them; that is your total unrealized P&L. Add realized gains and losses from positions you have already sold, plus dividends received, for the full picture. For a percentage, divide the total dollar P&L by total cost. If you deposited or withdrew money over time, a simple percentage on total cost can mislead, and an annualized money-weighted return gives a fairer measure.
Is a gain realized if I sell and immediately buy the shares back?
Yes. A sale realizes the gain or loss regardless of what you do next, and the new shares start a new holding period at the new price. For a loss, buying back substantially identical shares within 30 days triggers the wash sale rule described above.
The Bottom Line
Anyone tracking a stock position needs more than the gap between buy and sell prices to know what they actually kept. Measure the result as a percentage against an accurate cost basis, then add dividends and subtract commissions, margin interest and taxes. Annualizing returns and choosing tax lots carefully make the figures comparable across periods and can change the tax you owe on the same sale.











