How Long Do You Have to Live in a House to Avoid Capital Gains?

To avoid capital gains tax on the sale of your home, you generally have to live in it as your principal residence for at least two of the five years before you sell. Meet that threshold and you can exclude up to $250,000 of profit from your taxable income, or up to $500,000 if you’re married and filing jointly.1Office of the Law Revision Counsel. 26 USC 121 – Exclusion of Gain From Sale of Principal Residence Miss it by even a few months and the exclusion can vanish entirely, though several situations let you qualify on a shorter timeline.

The Two-Year Rule, in Detail

The exclusion comes from Internal Revenue Code Section 121, which imposes two separate requirements you have to satisfy during the five-year window ending on the sale date.2Internal Revenue Service. Topic No. 701, Sale of Your Home

The ownership test asks whether you held title to the property for at least 24 months during those five years. The use test asks whether you actually used it as your principal residence for at least 24 months during the same five-year period. The two periods can overlap, but they don’t have to, and neither one has to be a single continuous stretch. You could live in the house for 14 months, move out for a year, move back for 10 months, and still meet the use test.2Internal Revenue Service. Topic No. 701, Sale of Your Home

Because the window rolls, timing the sale matters. If you moved out more than three years ago, your remaining use months inside the five-year window are already shrinking, and waiting too long to sell can push you out of the exclusion entirely.

How Much Profit the Exclusion Covers

Meet both tests and you can exclude up to $250,000 of gain as a single filer or married filing separately, and up to $500,000 as a married couple filing jointly.3Internal Revenue Service. Publication 523 (2025), Selling Your Home

For the full $500,000, at least one spouse has to meet the ownership test and both spouses have to independently meet the use test. If only one spouse clears both, the couple is capped at $250,000.3Internal Revenue Service. Publication 523 (2025), Selling Your Home

There’s also a frequency limit. You can’t claim the exclusion if you already used it on another home sale within the two years before the current sale, measured sale date to sale date.1Office of the Law Revision Counsel. 26 USC 121 – Exclusion of Gain From Sale of Principal Residence So the two-year residency requirement isn’t the only two-year clock in play; the exclusion itself is a once-every-two-years benefit.

Unmarried co-owners each get their own $250,000 exclusion, so two qualifying co-owners can collectively exclude up to $500,000, with each claiming $250,000 against their share of the gain.2Internal Revenue Service. Topic No. 701, Sale of Your Home

What Happens to Gain Above the Exclusion

Profit above the $250,000 or $500,000 cap is taxed as a long-term capital gain, since a home held more than a year always qualifies for long-term rates. For 2026, the federal rate is 0%, 15%, or 20% depending on taxable income, with the 20% rate reserved for taxable income above roughly $545,000 for single filers and $613,000 for joint filers.

High earners face an additional 3.8% Net Investment Income Tax on capital gains when modified adjusted gross income exceeds $200,000 (single) or $250,000 (joint). The NIIT applies only to the gain that isn’t excluded under Section 121, and only to the extent income clears those thresholds.4Internal Revenue Service. Questions and Answers on the Net Investment Income Tax A joint-filing couple with a $600,000 gain would exclude $500,000, and the remaining $100,000 could be hit with both the 15% capital gains rate and the 3.8% NIIT depending on total income.

Selling Before Two Years: The Partial Exclusion

If you sell before hitting 24 months, you may still qualify for a prorated exclusion, but only if the sale happens for a qualifying reason: a job relocation, a health issue, or certain other unforeseen events.5Internal Revenue Service. Publication 523 (2025), Selling Your Home – Section: Does Your Home Qualify for a Partial Exclusion of Gain

For a work-related sale, your new workplace has to be at least 50 miles farther from the home than your old one was. If your previous office was 15 miles from home, the new one has to be at least 65 miles away. Starting a first job at least 50 miles from the home also counts.5Internal Revenue Service. Publication 523 (2025), Selling Your Home – Section: Does Your Home Qualify for a Partial Exclusion of Gain

Health-related sales qualify when the move is to get, provide, or make easier the treatment of a disease, illness, or injury for you or a family member. Other qualifying events include divorce or legal separation, death of a spouse or co-owner, the home being destroyed or condemned, and casualty loss from a natural disaster.5Internal Revenue Service. Publication 523 (2025), Selling Your Home – Section: Does Your Home Qualify for a Partial Exclusion of Gain

The math takes the shortest of three periods: how long you lived in the home, how long you owned it, or how long since you last claimed the exclusion on another sale. Divide that shortest period in months by 24, then multiply by $250,000 or $500,000. Fifteen months of use before a qualifying job relocation, filing single, yields an exclusion of 15/24 × $250,000, or $156,250.5Internal Revenue Service. Publication 523 (2025), Selling Your Home – Section: Does Your Home Qualify for a Partial Exclusion of Gain

If you sell early without a qualifying reason, there’s no partial exclusion. The entire gain is taxable.

Situations That Change the Two-Year Math

Divorce

If you receive a home from a spouse or ex-spouse as part of a divorce, you can count the time they owned it as time you owned it, which can satisfy the ownership test the day the transfer happens.3Internal Revenue Service. Publication 523 (2025), Selling Your Home And if a divorce decree requires you to let your ex-spouse continue living in the home, their time there counts toward your use test, so the moving-out spouse doesn’t lose eligibility just because a court ordered them out.

Surviving Spouses

A surviving spouse can claim the full $500,000 exclusion instead of the $250,000 single-filer amount, but only if the home is sold within two years of the spouse’s death. The couple must have met the ownership and use tests as of immediately before the death, and neither spouse can have used the exclusion in the prior two years.1Office of the Law Revision Counsel. 26 USC 121 – Exclusion of Gain From Sale of Principal Residence After that two-year window, the survivor drops to $250,000.

Military and Foreign Service

Active-duty military, Foreign Service officers, and intelligence community employees can elect to suspend the five-year test period for up to 10 years while serving on qualified official extended duty at a station at least 50 miles from the home. Extended duty means active duty under orders for more than 90 days or for an indefinite period.6Office of the Law Revision Counsel. 26 USC 121 – Exclusion of Gain From Sale of Principal Residence In practice, the five-year lookback can stretch to 15 years, so a service member who lived in a home for two years and then deployed for eight can still sell and claim the full exclusion. The election is made on the return for the year of the sale.

Inherited Homes

Inheriting a home doesn’t give you credit for the prior owner’s use. You still need to live there for two of the five years before selling to claim the exclusion. That usually matters less than it sounds, because your basis is stepped up to the fair market value on the date of death, which often shrinks or eliminates the gain in the first place.7Internal Revenue Service. Publication 551 (12/2025), Basis of Assets A house a parent bought for $80,000 that was worth $400,000 at death has a $400,000 basis in your hands; sell for $420,000 and the gain is $20,000.

Homes Acquired in a 1031 Exchange

If you got the home through a like-kind exchange, you have to hold it for at least five years from the acquisition date before the Section 121 exclusion is available, even if you converted it to a primary residence and lived there for the full two years.1Office of the Law Revision Counsel. 26 USC 121 – Exclusion of Gain From Sale of Principal Residence The two-year use requirement doesn’t override this longer holding period.

Traps That Survive the Two-Year Rule

Meeting the residency test doesn’t always mean the whole gain is excluded. Two situations carve out taxable pieces even for qualifying sellers.

The first is non-qualifying use. Any period after December 31, 2008, during which the property wasn’t your principal residence counts as non-qualifying use, and the share of your gain allocated to those periods can’t be excluded.1Office of the Law Revision Counsel. 26 USC 121 – Exclusion of Gain From Sale of Principal Residence The allocation is the ratio of non-qualifying months to total months of ownership. Own a home for 10 years, rent it out for 4 of them after 2008, and roughly 40% of your gain falls outside the exclusion.

The second is depreciation recapture. Any depreciation you claimed for renting the property or using part of it for business (after May 6, 1997) has to be recaptured as taxable income when you sell, regardless of whether you qualify for Section 121. Recaptured depreciation is taxed at a maximum federal rate of 25%, separate from the rate that applies to the rest of your gain.3Internal Revenue Service. Publication 523 (2025), Selling Your Home

Do You Even Have to Report the Sale?

If the entire gain fits inside your exclusion and you didn’t receive a Form 1099-S from the closing agent, you don’t have to report the sale at all.8Internal Revenue Service. Important Tax Reminders for People Selling a Home Most closings do generate a 1099-S, though, so most sellers should report the sale even when the gain is fully excluded.

When reporting is required, the capital gain portion goes on Form 8949 and Schedule D of Form 1040, with the exclusion noted so the IRS can see you qualified rather than simply skipped income. Depreciation recapture from business or rental use gets reported on Form 4797.3Internal Revenue Service. Publication 523 (2025), Selling Your Home