The basic calculation: sale price minus what you paid, minus improvements
Capital gains tax on a home sale is calculated by subtracting your cost basis from your sale price, then subtracting any exclusion you are may have access to to claim. The result is your taxable gain — the amount the IRS taxes.
The formula is: (Sale Price) − (Cost Basis) − (Exclusion) = Taxable Gain. Most homeowners owe no tax because the exclusion — up to $250,000 for single filers or $500,000 for married couples filing jointly — covers the entire gain. You only owe tax if your gain exceeds that threshold.
Cost basis is not just what you paid for the house. It includes the purchase price plus the cost of permanent improvements you made — a new roof, an addition, a new HVAC system, a deck. It does not include repairs (fixing a leaky roof) or maintenance (painting, landscaping). The distinction matters because improvements increase basis and reduce taxable gain.
Key Takeaways
- Your taxable gain is the sale price minus your cost basis (purchase price plus permanent improvements) minus your exclusion ($250,000 single, $500,000 married filing jointly).
- Most homeowners owe no capital gains tax because the exclusion covers their entire gain, but you must meet the ownership and use test: you owned and lived in the home for at least two of the last five years.
- Permanent improvements like a new roof or addition increase your cost basis and reduce taxable gain; repairs and maintenance do not.
- If your gain exceeds the exclusion, you owe tax at either 0%, 15%, or 20% depending on your total income for the year, not just the gain itself.
- You report the sale on Form 8949 and Schedule D, and you must file even if you owe no tax if you sold the home at a gain.
What counts as your cost basis
Cost basis starts with the purchase price you paid for the home. Add to that the cost of any permanent structural improvements — new roof, new foundation work, room additions, new HVAC or plumbing systems, deck or patio, new windows, insulation upgrades, or a new garage. These are capital improvements that add value or extend the life of the home.
Do not include repairs and maintenance. Painting the interior, fixing a leaky roof, patching drywall, replacing broken windows, or landscaping do not increase basis. The IRS distinguishes between improvements (which add basis) and repairs (which do not). When in doubt, ask yourself: does this add value to the home, or does it restore it to its previous condition? If it restores, it is a repair.
You will need receipts or invoices for improvements to prove the cost. Keep records of what you spent and what work was done. If you inherited the home or received it as a gift, your basis may be different — inherited homes receive a "step-up" in basis to the fair market value on the date of death, which usually eliminates capital gains tax entirely.
The ownership and use test: when you can claim the exclusion
You can only use the $250,000 or $500,000 exclusion if you meet the ownership and use test. You must have owned the home and lived in it as your primary residence for at least two of the five years before you sold it. The two years do not have to be consecutive, and they do not have to be the two years immediately before the sale.
If you owned the home for ten years but only lived in it for one year, you cannot claim the exclusion. If you owned it for three years and lived in it for two of those years, you can. If you sold it, bought another home, and then sold that one within two years, you can claim the exclusion on both if you meet the test for each.
If you do not meet the ownership and use test — for example, you inherited the home and sold it within a year — you cannot claim the exclusion. Your entire gain is taxable. There are narrow exceptions for job relocation, health issues, or unforeseen circumstances, but these require IRS approval and documentation.
How to calculate your taxable gain step by step
Step 1: Determine your sale price. This is the amount the buyer paid you, minus any selling costs you paid directly (real estate agent commission, title insurance, attorney fees, transfer taxes). These are called "selling expenses" and reduce your net proceeds and your sale price for tax purposes.
Step 2: Add up your cost basis. Start with what you paid for the home. Add the cost of all permanent improvements you made. Subtract any depreciation if you used part of the home for business or rental (this is rare for primary residences but matters if applicable).
Step 3: Calculate your gain. Subtract cost basis from sale price. This is your total gain, before any exclusion.
Step 4: Subtract your exclusion. If you meet the ownership and use test, subtract $250,000 (single) or $500,000 (married filing jointly). If the result is zero or negative, you owe no capital gains tax. If it is positive, that is your taxable gain.
Step 5: Determine your tax rate. Long-term capital gains tax rates are 0%, 15%, or 20%, depending on your total taxable income for the year, not just the gain. The IRS publishes income thresholds each year. For 2024, the 0% rate applies to single filers with taxable income up to $47,025; the 15% rate applies up to $518,900; and 20% applies above that. These thresholds change annually.
Example calculation for a typical home sale
You bought your home in 2015 for $300,000. You lived in it for nine years. You spent $50,000 on a kitchen renovation and $30,000 on a new roof — both permanent improvements. You sold it in 2024 for $550,000. Your real estate agent charged 6% commission ($33,000), and you paid $2,000 in closing costs.
Sale price: $550,000 − $33,000 − $2,000 = $515,000. Cost basis: $300,000 + $50,000 + $30,000 = $380,000. Total gain: $515,000 − $380,000 = $135,000. You are married filing jointly and meet the ownership and use test, so you subtract $500,000 — but your gain is only $135,000, so your taxable gain is $0. You owe no capital gains tax.
Now assume you sold for $900,000 instead. Sale price: $900,000 − $33,000 − $2,000 = $865,000. Total gain: $865,000 − $380,000 = $485,000. Taxable gain: $485,000 − $500,000 = $0 (still no tax). But if you sold for $950,000: sale price $915,000, total gain $535,000, taxable gain $35,000. At the 15% rate, you would owe $5,250 in federal capital gains tax.
What to do if you do not meet the ownership and use test
If you owned the home for less than two of the last five years, or did not live in it as your primary residence for that period, you cannot claim the exclusion. Your entire gain is taxable. This happens most often when someone inherits a home and sells it quickly, or buys a home as an investment and then sells it.
There are exceptions for job relocation, health issues, or unforeseen circumstances like divorce or death in the family. These are called "safe harbor" exceptions. If you may have access to, you can claim a reduced exclusion — a fraction of the $250,000 or $500,000 based on how long you actually owned and used the home. You must file Form 8801 and provide documentation of the reason.
If you do not may have access to for an exception, you owe tax on the full gain at your long-term capital gains rate (assuming you held the home for more than one year). If you held it for one year or less, the gain is taxed as ordinary income at your regular tax bracket, which is usually higher.
Reporting the sale on your tax return
You report a home sale on Form 8949 (Sales of Capital Assets) and Schedule D (Capital Gains and Losses). You must file these forms even if you owe no tax, as long as you had a gain. If you had a loss (sold for less than your basis), you generally cannot deduct it — home losses are not deductible for personal residences.
On Form 8949, you list the date acquired, date sold, sales price, cost basis, and gain or loss. On Schedule D, you summarize long-term and short-term gains and losses. If you have other capital gains or losses from investments or other property sales, they go on the same forms and may offset each other.
If you use tax software or work with a tax professional, they will guide you through these forms. The IRS also publishes Publication 523 (Selling Your Home), which walks through the calculation and provides worksheets. Keep all documentation — the purchase deed, improvement receipts, closing statements, and the sale settlement statement — for at least three years in case of audit.
Frequently Asked Questions
Do I have to report the sale if I owe no tax?
Yes, you must file Form 8949 and Schedule D if you sold your home at a gain, even if the gain is entirely covered by the exclusion and you owe no tax. The IRS wants a record of the transaction. If you sold at a loss, you do not have to report it (losses on personal residences are not deductible).
What if I rented out part of my home or used it for a home office?
If you used part of the home for business or rental, that portion does not may have access to for the exclusion. You must calculate the gain on the business-use portion separately and pay tax on it. You may also owe depreciation recapture tax. Consult a tax professional if this applies to you.
Can I claim the exclusion if I am not married but lived with a partner?
No. The $500,000 exclusion is only for married couples filing jointly. If you are single, divorced, or widowed, your exclusion is $250,000. If you are married but file separately, each spouse gets $250,000. Unmarried partners cannot combine exclusions.
What if I sold the home at a loss?
You cannot deduct a loss on the sale of your primary residence. If you sold for less than your cost basis, you simply do not report it. Losses are only deductible on investment property or business property, not personal homes.
How do I know if an expense is an improvement or a repair?
Improvements add value or extend the life of the home (new roof, addition, new HVAC). Repairs restore it to its previous condition (fixing a leaky roof, patching drywall). When in doubt, keep the receipt and ask a tax professional. If the work is part of a larger project that adds value, it may count as an improvement even if it also fixes something.