
If you sell your home and buy another, do you owe tax on the gain? Spain's reinvestment exemption, with or without a mortgage
You sell the flat you’ve lived in for years, make a gain on the sale and buy another home to live in. It feels like nothing should happen: you haven’t “cashed out”, you’ve just swapped one home for another. But for the Spanish Tax Agency (Agencia Tributaria) the gain exists from the day you sign the sale, and if you do nothing, it expects you to declare it and pay tax on it.
There’s an exemption built exactly for this. The problem is that many people get the math wrong on how much they actually need to reinvest, and the mortgage left on the home they sell changes it quite a lot (in their favour, although almost nobody knows). Let’s go through it calmly: what’s exempt, what isn’t, how the mortgage fits into the calculation and which tax you pay separately even if you reinvest every last euro.
The exemption, in one sentence
If you sell your main home (not a second residence, not a flat you had rented out) and reinvest the full amount obtained in buying a new main home, the gain on the sale is exempt from income tax (IRPF).1 If you only reinvest part of it, only the share of the gain proportional to what you reinvested is exempt, and the rest is declared as an ordinary capital gain.2
Notice the key words: amount obtained. It isn’t the gain, it’s what you get from the sale. That’s the most common mistake: thinking it’s enough to reinvest what you gained. If you sell for €300,000 a flat that cost you €200,000, putting €100,000 into the new home won’t do.
If there was a mortgage left, you need to reinvest less
When you sell a home with a mortgage still outstanding, part of the sale money goes straight to paying off what was left of the loan. The rules take that into account: if you bought the home you’re selling with a loan, the “amount obtained” is the sale price minus the principal still outstanding at the time of the sale.3 What the bank keeps, you don’t have to reinvest.
With round numbers:
- You sell your main home for €300,000.
- Of that €300,000, €100,000 goes to paying off the remaining mortgage.
- Your amount obtained for the exemption isn’t €300,000: it’s €200,000 (300,000 − 100,000).
- Your gain on the sale is €100,000 (you bought it for €200,000, costs included).
If the new home costs you €200,000 or more, you’ve reinvested 100% and the whole gain is exempt. If it costs €150,000, you’ve reinvested 75% (150,000 / 200,000), so 75% of the gain is exempt: €75,000 free of income tax and €25,000 taxed in the savings base.2
Without the mortgage, the same €150,000 purchase would only be 50% of €300,000, and you’d pay tax on half the gain. The mortgage doesn’t shrink your exemption: it lowers the bar.
You can pay for the new home with another mortgage
The second usual question: “if I use the sale money for something else and pay for the new home with a mortgage, do I lose the exemption?” No. What counts is the price of the new home, whether you pay cash or with a loan: it doesn’t have to be the same euros you got from the sale. That’s what the Spanish Tax Agency says in its income tax manual, following a 2020 Supreme Court ruling.4
In the example above, if you buy the new home for €220,000 with a €180,000 mortgage, you’ve reinvested €220,000, more than your €200,000 amount obtained: full exemption.
The timeline you need to meet
The purchase and the sale don’t have to happen on the same day. You have some room, with these rules:5
- Two years, before or after the sale, to buy the new home. You can buy first and sell later, or the other way round.
- If you sell in one year and reinvest in a later one, you must state your intention to reinvest in the tax return for the year of the sale.
- If the sale price is paid in instalments, each instalment counts as reinvested if you put it into the new home within the year you receive it.
And both homes have to be “main homes” for real:6
- The one you sell: it must have been your residence for at least three years in a row (except for forced moves, such as a job transfer or a separation). If you had already moved out, it’s enough that it was your main home at any point in the two years before the sale.
- The one you buy: you must move in within twelve months of buying it and live there for at least three years. If you buy, don’t move in and rent it out, you lose the exemption and have to file a supplementary return for the year of the sale, with late-payment interest.7
Being registered at the address (empadronamiento) doesn’t prove on its own that you live there: it’s a question of fact, shown with everything else (utilities, post, the children’s school). We cover it in detail for the reduced ITP rate, which asks for the same thing.
What you pay anyway, however much you reinvest
The exemption covers income tax and nothing else. The municipal capital gains tax (plusvalía municipal, the tax on the increase in value of urban land) is a separate tax your town hall charges on the rise in value of the land since you bought, and reinvesting doesn’t affect it: you pay it whether you reinvest or not.8
In other words, you can bring the income tax on the sale down to zero and still get a plusvalía bill of several hundred or several thousand euros, depending on the town and how long you owned the flat. If you sell from 1 December 2026, the new maximum coefficients of the housing decree also apply, which we cover in everything that changes with RDL 29/2026. Count on that payment separately when you work out what you’ll have left.
If you’re 65 or older, the math is different
If you’re 65 or older (or in a situation of severe or major dependency), the gain on selling your main home isn’t taxed even if you reinvest nothing: not in another home, not anywhere.9 It’s a separate exemption from the reinvestment one, and much simpler. You still pay the plusvalía municipal, though.
And if you live in a foral territory
Álava, Bizkaia, Gipuzkoa and Navarre have their own income tax, with a main-home reinvestment exemption that follows the same idea but with its own wording and deadlines.10 If you’re taxed there, don’t apply this article directly: check with your Hacienda Foral.
Run the numbers before you sign
Selling a home to buy another isn’t a surprise: you see it coming months ahead. That’s why it pays to do the math before signing anything: how much you’ll have left after paying off the mortgage, how much the new home has to cost so you owe no tax, and how much to set aside for the plusvalía and the purchase costs (notary, land registry and transfer tax or VAT, which we cover in the taxes and costs of buying a home). And if instead of buying another home you’re keeping the other half of yours (from your ex, from your sibling), what you pay is something else: see buying out a co-owner.
How does Cuéntamo help with this?
The home buying costs calculator tells you, for your region, how much you need saved on signing day on top of the price, without signing up. And in Cuéntamo, when you sign (“I’ve signed”, in your savings goal for the home), you register the new home with its linked mortgage and follow its repayment month by month as part of your net worth, alongside the rest of your accounts.
Frequently asked questions
What happens if I sell my main home and reinvest nothing?
You pay tax on the whole gain, as an ordinary capital gain, in the savings base. The exemption only applies if you buy another main home, and in proportion to what you reinvest. The exception is people aged 65 or over, who don’t pay even if they don’t reinvest.
Do I only have to reinvest what I gained?
No. You have to reinvest the amount obtained from the sale, not the gain. If you only reinvest the equivalent of the gain, the exemption will be partial.
I had a mortgage on the home I sold. Do I count the full sale price?
No. The outstanding principal of the loan you used to buy the home you sold is subtracted from the sale price. Your amount obtained is the price minus what was left to repay, and that’s what you need to reinvest.
Can I pay for the new home with a mortgage and keep the exemption?
Yes. What counts is the price of the new home, whether you pay cash or with a loan. You don’t need to use the same money from the sale.
If I reinvest everything, do I also avoid the municipal capital gains tax?
No. The plusvalía municipal is a different tax from income tax and the reinvestment exemption doesn’t affect it: you pay it anyway.
Figures for 2026. The main-home reinvestment exemption has been in force since 2007 (Law 35/2006) and its conditions, in their current wording, since 2013 (art. 41 of the Personal Income Tax Regulations).
This article is checked against official sources and reviewed periodically. If you spot anything out of date, email us at [email protected].
Article 38.1 of Law 35/2006 on Personal Income Tax: gains from selling the taxpayer’s main home may be excluded from tax “provided that the total amount obtained from the transfer is reinvested in the acquisition of a new main home under the conditions laid down in the regulations”. ↩︎
Article 38.1, second paragraph, of Law 35/2006 on Personal Income Tax, and article 41.4 of the Personal Income Tax Regulations: if less than the total is reinvested, only the proportional share of the gain corresponding to the amount reinvested is excluded from tax. ↩︎ ↩︎
Article 41.1 of the Personal Income Tax Regulations (Royal Decree 439/2007): where the taxpayer used outside financing to buy the home being sold, the total amount obtained is, for these purposes only, the sale value minus the loan principal still outstanding at the time of the sale. ↩︎
Spanish Tax Agency, Income Tax Practical Manual 2025, “Other requirements and conditions for applying the exemption” (in Spanish): the full acquisition value of the new home is taken into account “regardless of whether it has been paid or financed”, citing Supreme Court Ruling 1230/2020 of 1 October. ↩︎
Article 41.3 of the Personal Income Tax Regulations: reinvestment in one go or in stages within no more than two years from the sale (or in the two previous years, if the new home was bought first), sales paid in instalments, and the obligation to state the intention to reinvest in the return for the year of the sale. ↩︎
Article 41 bis of the Personal Income Tax Regulations: continuous residence of at least three years, effective occupation within twelve months of acquisition, and sale of a home that was the main home on any day of the two years before the sale. ↩︎
Article 41.5 of the Personal Income Tax Regulations: failing any of the conditions makes the corresponding part of the gain taxable, through a supplementary return for the year it was obtained, with late-payment interest. ↩︎
The tax on the increase in value of urban land (IIVTNU, “plusvalía municipal”) is regulated in articles 104 onwards of the Consolidated Text of the Local Finance Law (Royal Legislative Decree 2/2004), as a municipal tax separate from income tax. ↩︎
Article 33.4.b) of Law 35/2006 on Personal Income Tax: there is no capital gain or loss “on the transfer of their main home by people over 65 or by people in a situation of severe or major dependency”. ↩︎
Álava, Bizkaia, Gipuzkoa and Navarre regulate their own income tax under the Economic Agreement and Covenant, with a similar main-home reinvestment exemption but their own rules and deadlines. ↩︎