The answer
For each partial sale, subtract that portion’s cost basis and its sell fee from the sale proceeds. Allocate the original purchase cost, including any buy fee, across the units you bought. For each sale: realized profit or loss = quantity sold × sale price − sell fee − allocated cost basis. Calculate each sale separately, then add the three results for the combined realized result. In a hypothetical example, buying 0.03 BTC at $40,000 with a 0.1% buy fee gives a total cost basis of $1,201.20, or $400.40 per BTC. Selling 0.01 BTC at $45,000, $42,000 and $38,000, each with a 0.1% sell fee, produces $49.15, $19.18 and a $20.78 loss. Together, the three sales realize $47.55 before any excluded costs or taxes.
Start with the original cost basis
Cost basis is the amount assigned to the units you later sell. For this example, assume one purchase of 0.03 BTC at $40,000 per BTC and a buy fee of 0.1% charged in the quote currency. The purchase value is 0.03 × $40,000 = $1,200. The buy fee is $1,200 × 0.001 = $1.20, so the total modeled cost basis is $1,201.20.
Divide that total basis by the 0.03 BTC bought: $1,201.20 ÷ 0.03 = $40,040 per BTC. Each 0.01 BTC sold is assigned 0.01 × $40,040 = $400.40 of the original cost. This proportional allocation assumes the three sales all come from that same purchase and treats the buy fee as part of its cost.
If units came from multiple purchases at different prices, do not automatically use one blended per-unit amount. Track the purchase lots and use the cost-basis method applicable to your records and jurisdiction. This example demonstrates the arithmetic for one lot; it does not determine tax treatment.
Sale one: price above the allocated cost
Sell 0.01 BTC at $45,000 per BTC. Gross proceeds are 0.01 × $45,000 = $450. At a 0.1% sell fee, the fee is $450 × 0.001 = $0.45. Proceeds after the fee are $449.55. The cost basis allocated to this 0.01 BTC is $400.40, so this sale’s realized result is $449.55 − $400.40 = $49.15 profit.
Record the sold quantity, gross proceeds, sell fee, allocated basis and result before moving to the next sale. Keeping the lines separate makes it clear which part of the position has already been closed.
Sale two: calculate it from its own fill
Sell another 0.01 BTC at $42,000 per BTC. Gross proceeds are 0.01 × $42,000 = $420. The 0.1% sell fee is $0.42, leaving $419.58 after the fee. Subtract the $400.40 basis allocated to this portion: $419.58 − $400.40 = $19.18 profit.
The first sale’s price does not change the second sale’s realized result. Each tranche has its own execution price and fee, but both use the correct portion of the original basis under the single-lot assumption.
Sale three: a sale can realize a loss
Sell the final 0.01 BTC at $38,000 per BTC. Gross proceeds are $380. The 0.1% sell fee is $0.38, leaving $379.62. After subtracting the $400.40 allocated basis, the result is $379.62 − $400.40 = −$20.78, a realized loss of $20.78.
A lower sale price can produce a loss on this portion even when earlier portions were profitable. That is why a single average exit price can hide what happened on each trade. The signed result for this sale is negative $20.78.
Add the three realized results
Now add the separate outcomes: $49.15 + $19.18 − $20.78 = $47.55. This is the combined modeled realized profit across the three sales. As a cross-check, total gross proceeds are $450 + $420 + $380 = $1,250. Total sell fees are $0.45 + $0.42 + $0.38 = $1.25. Net proceeds are $1,248.75. Subtract the $1,201.20 original cost basis: $1,248.75 − $1,201.20 = $47.55.
The two approaches agree because all 0.03 BTC was sold, all three amounts came from the same purchase lot, and the only modeled fees are the 0.1% buy fee and the three 0.1% sell fees. If some of the original position remains unsold, do not subtract the full original basis from the proceeds of only the completed sales. Subtract only the basis allocated to the quantities already sold.
Use one row for every sale or fill
A practical record has one row per completed sale or execution fill. Include the date, asset, quantity sold, execution price, gross proceeds, sell fee, allocated cost basis and realized result. If one order fills at multiple prices or has separately rounded fees, using the actual fill records can make the arithmetic easier to reconcile with the exchange statement.
A crypto profit calculator can check a single buy-and-sell scenario when you enter the relevant prices, quantity and fee rates. For several sales, calculate each tranche against its own proceeds and allocated basis, then total the results. The calculator uses values you enter and does not retrieve market prices. You can also use a crypto fee and profit calculator to check the arithmetic for one tranche at a time.
For another one-sale example, see the guide to finding a target-profit sell price after fees. That page solves for a sale price; the method here totals realized results from multiple completed sales.
Fees, rounding and what this example excludes
This example assumes the buy fee is added to quote-currency cost basis and each sell fee is deducted from that sale’s quote-currency proceeds. If a fee is charged in the asset itself or another token, use the actual fee amount and quantity from the trade record rather than forcing it into this assumption. Exchange fee rounding can also make the final cents differ from a calculation using unrounded percentages.
The arithmetic excludes spread, slippage, network or withdrawal fees, borrowing or funding costs and taxes. It assumes the sold quantities total the original 0.03 BTC. The prices and fee rates are hypothetical inputs, not live market data. This page explains a calculation and is not financial, accounting or tax advice; keep the transaction records and use the rules that apply to your situation.
Formula for each partial sale
Let Q be the quantity from the original purchase, B its buy price, b its buy fee rate, qᵢ the quantity in sale i, Sᵢ that sale’s price and sᵢ its sell fee rate. Under the single-lot, quote-currency fee assumption, total original basis is Q × B × (1 + b), and the basis assigned to sale i is qᵢ × B × (1 + b). Its result is:
Resultᵢ = qᵢ × Sᵢ × (1 − sᵢ) − qᵢ × B × (1 + b)
Add Result₁, Result₂ and Result₃ for the total across three sales. Fee rates are decimals in this equation: 0.1% = 0.001. The formula assumes positive quantities and that the sold units belong to the stated original purchase lot.