Pilar Ortega, a teacher in Valladolid, bought her flat in 2011 for 170,000 € and paid 12,000 € in notary's fees, land registry fees and tax. In March 2026 she sells it for 310,000 €. The estate agency and the other costs of the sale take 11,000 €. At the signing before the notary, the bank collects the 88,000 € of mortgage she still owed. Pilar has worked out that she has "made" 117,000 € and asks whether it is enough to put that amount into the terraced house she wants to buy in Arroyo de la Encomienda, a town next to Valladolid. The short answer is no: what has to be reinvested is much more than the gain, although quite a lot less than the sale price.
Three figures that get mixed up
A sale produces three different numbers, and each one is used for something different:
| Figure | How it is obtained | What it is for |
|---|---|---|
| Transfer value | Sale price minus costs and taxes paid by the seller (art. 35.2 of the IRPF Law) | The starting point for everything |
| Capital gain | Transfer value minus acquisition value | What is taxed if there is no exemption |
| Total amount obtained | Transfer value minus the principal of the loan outstanding at the time of sale | What has to be reinvested |
The law refers to the third one. Article 38.1 of the law on IRPF (Spanish personal income tax) allows the gain to be excluded from tax "provided that the total amount obtained on the transfer is reinvested" in a new main home. And article 41.1 of the IRPF Regulations specifies that, if the home sold was bought with borrowed money, the total amount obtained is the one resulting "from reducing the transfer value by the principal of the loan" still to be repaid at the time of the sale.
The logic is simple: the money the bank keeps at the notary's office never reaches your hands, so you are not required to reinvest it. But the gain on its own is too short a figure, because the amount obtained also contains the money you put in from your own pocket at the time, which you are now getting back.
Pilar's figures
- Sale price: 310,000 €.
- Costs of the sale borne by Pilar: 11,000 €.
- Transfer value: 310,000 − 11,000 = 299,000 €.
- Acquisition value: 170,000 + 12,000 = 182,000 €.
- Capital gain: 299,000 − 182,000 = 117,000 €.
- Principal of the mortgage outstanding on the day of the sale: 88,000 €.
- Total amount obtained: 299,000 − 88,000 = 211,000 €.
Pilar has to put 211,000 € into the new main home for the 117,000 € gain to be fully exempt. If she puts in less, the exemption is reduced in the same proportion. The guide on how to calculate the amount to reinvest covers more scenarios, and working out the gain with depreciation and improvements is explained in calculating the gain on a sale.
What happens depending on how much she puts into the new house
The proportion rule in the second paragraph of article 38.1 works like this: exempt part = gain × amount reinvested ÷ total amount obtained.
| Amount reinvested | Calculation | Exempt gain | Taxable gain |
|---|---|---|---|
| 117,000 € (only the "gain") | 117,000 × 117,000 ÷ 211,000 | 64,876.78 € | 52,123.22 € |
| 160,000 € | 117,000 × 160,000 ÷ 211,000 | 88,720.38 € | 28,279.62 € |
| 211,000 € | 117,000 × 211,000 ÷ 211,000 | 117,000.00 € | 0 € |
| 299,000 € (the whole transfer value) | Capped at 211,000 | 117,000.00 € | 0 € |
The first row is the mistake Pilar was about to make: reinvesting only the gain leaves more than 52,000 € subject to tax in the savings base. The last row shows the opposite: going beyond the amount obtained adds nothing. The exemption never exceeds one hundred per cent of the gain.
The question if I reinvest only part, how much is exempt? works through the proportion in more detail and with the effect of the mortgage on the new home.
And if there was no mortgage?
With no loan outstanding, the total amount obtained is the same as the transfer value. If Pilar had finished paying off her mortgage in 2024, she would have to reinvest the full 299,000 €. It is a result that surprises people: someone who has paid off their whole loan needs to reinvest more than someone who still owes the bank, because they receive more cash from the sale.
The same thing happens in reverse with an early repayment shortly before selling. If someone pays off the mortgage with their savings a month before signing the sale, on the day of the transfer there is no principal outstanding any more and the figure to reinvest goes up. The Regulations look at the loan outstanding "at the time of the transfer", not the one that existed months earlier.
Article 41.1 of the Regulations refers to the borrowed money used to acquire the home being sold and to the principal outstanding. Interest, the early repayment fee or a personal loan taken out later for something else do not reduce the amount to reinvest. If the mortgage was increased at some point to finance a car or the renovation of another home, that part deserves an examination of its own: we do not take it for granted that Hacienda, as the Spanish tax office is commonly called, will accept it as financing for the purchase.
What counts as invested in the new home
On the purchase side, what counts is what is applied to acquiring the new main home within the time limit: the price and, in principle, the costs and taxes of the purchase that form its acquisition value. The rule does not require the same money that came from the sale to be used, but that the amount reinvested reaches the figure obtained. When amounts financed with a new loan count is a question worth reviewing with the loan deed in front of you, because the Regulations speak of putting amounts towards paying the price, and that nuance is debated.
An example for Pilar. The terraced house costs 260,000 € plus about 20,000 € of purchase costs. If she pays 211,000 € out of her own pocket and finances the rest, in principle she reaches the figure. If instead she takes out a mortgage of 200,000 € and puts in only 80,000 € of what she obtained from the sale, the rest of that money stays in her account and it will be necessary to assess what part of what was paid with the loan counts as reinvestment, and when.
For us to study your specific figures you can use the reinvestment form: with the sale deed, the deed of the original purchase and the bank certificate of the balance outstanding on the day of the sale, the calculation can be done without assumptions.
Selling a home owned jointly
When the home belongs to two people, each of them is a taxpayer for their own share. If Pilar had owned it 50 % with her brother, each would have a gain of 58,500 €, an amount obtained of 105,500 € and their own decision on whether to reinvest. The brother may not reinvest and pay the tax, while Pilar applies the full exemption. Nor does one person's exemption carry the other along: each owner has to meet, on their own, the requirement that the home was their main residence. If, in addition, the new one is bought jointly with a partner, what counts as reinvested by each of them is what they contribute for their share, and it is advisable for the deeds and the payments to reflect that.
The time limit to complete the figure
The reinvestment does not have to be made all at once. Article 41.3 of the Regulations allows it to be made "in one go or in successive stages" over the two years following the sale, and also allows what was obtained to be used to pay for a home bought in the two previous years. If the figure is not completed in the same year as the sale, the return for that year has to record the intention to reinvest; we explain this in how the intention to reinvest is declared. How the dates are counted is set out in the two years: from when and until when.
What is best avoided
There are three decisions that tend to be taken in a hurry and reduce the exemption for no reason. The first is accepting the gain calculated by the bank or the estate agency, which almost never deducts the costs properly. The second is paying off the old mortgage with savings before the sale in the belief that "it comes out cleaner that way". The third is leaving part of the sale money in a deposit while waiting for building work on the new house without calculating whether what is finally paid within the time limit will reach the figure. In all three cases the outcome cannot be guaranteed in advance, and it is worth doing the sums before signing.
The reinvestment exemption, with its time limits, its calculations and the return for the year of the sale, is covered on the Salama Tax page devoted to selling your main home, which also sets out which documents are needed to review it.