Recommended resources
The freely available resources this lesson will direct you to.
- “Así se calcula la GANANCIA PATRIMONIAL en Hacienda (PASO A PASO REAL)” 🏚️www.youtube.com
- Renta 2024 - Cómo incluir la venta de un inmueblewww.youtube.com
- Ganancias patrimoniales derivadas de la venta de inmueblessede.agenciatributaria.gob.es
- Cómo Calcular la Ganancia Patrimonial al Vender un Inmuebleconsult.tax
Hello! Welcome back to our module on the taxation of Spanish real estate sales.
In the last lesson, we took a deep dive into calculating the valor de adquisición (adjusted acquisition cost), which forms the cost basis of your investment. We saw how it's composed of the purchase price, acquisition costs, and improvements, and importantly, how it's reduced by the depreciation you've claimed over the years.
Today, we'll complete the equation. This lesson focuses on computing the final profit or loss from a sale for tax purposes. Our learning outcome is to compute the gain subject to IRPF capital gains tax from a Spanish property sale. To do this, we'll first define the "transmission value" and then subtract the acquisition value we've already mastered.
The Fundamental Formula for Capital Gains
The profit you make on a property sale is known in Spanish tax terminology as a ganancia patrimonial. The core calculation is straightforward:
Where:
- Valor de Transmisión (Transmission Value): The net proceeds you receive from the sale.
- Valor de Adquisición (Adjusted Acquisition Value): The adjusted cost basis we calculated in the previous lesson.
This image provides a great visual overview of the formula and its components.

Our first task is to understand and calculate the Valor de Transmisión.
1. Calculating the 'Valor de Transmisión' (Transmission Value)
The transmission value isn't simply the sale price. It's the sale price minus all the expenses and taxes you incurred directly as a result of the sale.
The formula is:
Common deductible expenses for the seller include:
- Plusvalía Municipal: The local tax on the increase in land value.
- Real Estate Agency Commission: The fee paid to the agent who handled the sale.
- Notary and Registry Fees: Costs related to formalizing the sale deed, though often paid by the buyer, can sometimes be borne by the seller.
- Mortgage Cancellation Fees: Any administrative or notary costs to cancel the existing mortgage on the property.
- Legal Fees: Costs for lawyers involved in the transaction.
The following videos from the Agencia Tributaria and a tax advisor provide practical walkthroughs of these costs.
Renta 2024 - Cómo incluir la venta de un inmueble
First, let's hear the official definition from the Agencia Tributaria. This short clip from their tax declaration tutorial clearly explains what reduces the transmission value.
Watch from 01:00 to 01:34. The video lists key transmission expenses like 'plusvalía', mortgage cancellation, registry, and notary fees.
“Así se calcula la GANANCIA PATRIMONIAL en Hacienda (PASO A PASO REAL)” 🏚️
This next video offers a very practical perspective, showing how these expenses are entered into the tax software and explicitly mentioning the real estate agency commission.
Watch from 01:56 to 02:57. The speaker details how to input the sale price and lists the common deductible expenses, giving a clear example.
2. Putting It All Together: A Full Calculation
Now, let's combine what we learned in the last lesson with our new knowledge of the transmission value to calculate a full capital gain.
Let's use the example from the previous lesson and add sale details:
Scenario:
- You sell the property for €280,000.
- You pay a real estate agency commission of €14,000.
- You pay
plusvalía municipalof €4,000. - Other selling costs (notary, etc.) are €1,000.
Recall from the previous lesson:
- Purchase Price: €200,000
- Acquisition Costs: €18,000
- Improvements: €12,000
- Holding/Rental Period: 6 years
- Adjusted Acquisition Cost (
Valor de Adquisición): €198,608
Calculation:
-
Calculate the Transmission Value (
Valor de Transmisión)- Sale Price: €280,000
- Total Transmission Costs: €14,000 (agency) + €4,000 (plusvalía) + €1,000 (other) = €19,000
- Valor de Transmisión = €280,000 - €19,000 = €261,000
-
Calculate the Capital Gain (
Ganancia Patrimonial)- Ganancia Patrimonial = Valor de Transmisión - Valor de Adquisición
- Ganancia Patrimonial = €261,000 - €198,608 = €62,392
In this scenario, the gain subject to IRPF tax is €62,392.
The article below provides another clear, step-by-step example you can review.
Cómo Calcular la Ganancia Patrimonial al Vender un Inmueble Arrendado
To solidify this calculation, review the example in this article. It clearly demonstrates the process for a rented property, highlighting the impact of amortization.
Quickly review the sections 'Valor de Transmisión del Inmueble' and 'Valor de Adquisición del Inmueble', then focus on the 'Ejemplo de Cálculo' and 'Resultado del Cálculo' sections. Notice how they arrive at the final gain by subtracting the adjusted acquisition value from the transmission value.
3. An Important Exception: The Transitional Regime (Régimen Transitorio)
For properties acquired before December 31, 1994, Spanish tax law includes a special transitional regime that can significantly reduce the taxable capital gain. This rule is a holdover from an old system where gains were reduced based on the holding period.
While the old system is gone, this regime "grandfathers in" a reduction for the portion of the gain generated before January 20, 2006.
This is a complex rule, so let's break it down using the official guidance from the Agencia Tributaria.
Ganancias patrimoniales derivadas de la venta de inmuebles
The following text from the Agencia Tributaria is the definitive source on this rule. It's dense but essential for understanding this important exception.
First, read the section 'Régimen transitorio' carefully. It outlines the general rules. Then, study the 'Ejemplo' provided. We will walk through this example step-by-step below.
Let's dissect the example from the resource to understand the logic:
Key Data from the Example:
- Acquisition Date: Jan 1, 1991 (before 1994, so the rule applies)
- Transmission Date: Dec 31, 2019
- Acquisition Value: €100,000
- Transmission Value: €300,000
- A previous sale in 2015 used up €200,000 of a €400,000 limit.
Calculation Steps:
-
Calculate the Total Gain:
- €300,000 (Transmission) - €100,000 (Acquisition) = €200,000
-
Isolate the Gain Generated Before Jan 20, 2006:
- This is done by prorating the gain based on the holding period.
- Total days held: 10,591 (from 1991 to 2019)
- Days held before Jan 20, 2006: 5,498
- Gain generated before 2006 = €200,000 * (5,498 / 10,591) = €103,824
-
Apply the €400,000 Transmission Value Limit:
- The reduction can only be applied to gains corresponding to a cumulative transmission value of up to €400,000 from all sales since 2015.
- The previous sale used €200,000 of this limit.
- For the current sale, only €400,000 - €200,000 = €200,000 of the €300,000 transmission value is eligible for the reduction.
- Therefore, we must find the portion of the pre-2006 gain that corresponds to this eligible part of the transmission value:
- Gain susceptible to reduction = €103,824 * (€200,000 / €300,000) = €69,216
-
Calculate the Reduction Amount:
- Years of ownership before Dec 31, 1996 (rounded up): 6 (1991, 92, 93, 94, 95, 96).
- Years exceeding 2: 6 - 2 = 4 years.
- Reduction percentage: 11.11% per year = 4 * 11.11% = 44.44%.
- Reduction amount = €69,216 * 44.44% = €30,759.60
-
Calculate the Final Taxable Gain:
- Total Gain - Reduction = €200,000 - €30,759.60 = €169,240.40
As you can see, this rule reduced the taxable gain by over €30,000. It's a niche but powerful rule if you're dealing with long-held properties.
4. Updating Our Python Model
Let's extend our SpanishRentalProperty class to automate the standard capital gain calculation. We'll add a method that takes the sale details and uses our existing calculate_adjusted_acquisition_cost method to find the final gain.
Note: For simplicity, this code will not implement the complex logic of the transitional regime. It will focus on the standard calculation, which applies to the vast majority of transactions.
# Continuing from the previous lesson's SpanishRentalProperty class
class SpanishRentalProperty:
# ... (all previous methods: __init__, calculate_adjusted_acquisition_cost, etc.)
# ... previous code ...
def __init__(self, property_data: dict, owner_data: dict):
"""
Initializes the property model with raw data.
"""
self.property_data = property_data
self.owner_data = owner_data
self.results = {}
def calculate_adjusted_acquisition_cost(self, holding_period_years: int, total_improvement_costs: float) -> float:
"""
Calculates the adjusted acquisition cost ('valor de adquisición') at the end of a holding period.
"""
price = self.property_data['purchase']['price']
acq_costs = self.property_data['purchase'].get('acquisition_costs', 0)
initial_cost_base = price + acq_costs
cost_base_with_improvements = initial_cost_base + total_improvement_costs
land_value_proportion = self.property_data['purchase']['land_value'] / price
depreciation_base_building = initial_cost_base * (1 - land_value_proportion)
annual_depreciation = depreciation_base_building * 0.03
total_depreciation = annual_depreciation * holding_period_years
adjusted_acquisition_cost = cost_base_with_improvements - total_depreciation
return adjusted_acquisition_cost
def calculate_capital_gain(self, sale_price: float, transmission_costs: float, holding_period_years: int, total_improvement_costs: float) -> float:
"""
Computes the capital gain (ganancia patrimonial) from a property sale.
:param sale_price: The final sale price of the property.
:param transmission_costs: All deductible costs associated with the sale (agency, plusvalia, etc.).
:param holding_period_years: The number of years the property was held and rented.
:param total_improvement_costs: The total cost of capital improvements.
:return: The capital gain subject to tax.
"""
# 1. Calculate the transmission value
valor_de_transmision = sale_price - transmission_costs
# 2. Calculate the adjusted acquisition cost by calling our previous method
valor_de_adquisicion = self.calculate_adjusted_acquisition_cost(
holding_period_years=holding_period_years,
total_improvement_costs=total_improvement_costs
)
# 3. Calculate the gain
capital_gain = valor_de_transmision - valor_de_adquisicion
print(f"--- Capital Gain Calculation ---")
print(f"{'Sale Price':<40}: €{sale_price:,.2f}")
print(f"{'Transmission Costs':<40}: -€{transmission_costs:,.2f}")
print(f"{'Valor de Transmisión':<40}: €{valor_de_transmision:,.2f}")
print(f"{'Valor de Adquisición (Adjusted)':<40}: -€{valor_de_adquisicion:,.2f}")
print("-" * 50)
print(f"{'Capital Gain (Ganancia Patrimonial)':<40}: €{capital_gain:,.2f}")
return capital_gain
# --- Example Usage ---
if __name__ == '__main__':
# Using the same data as our manual example
sample_property = {
"purchase": {
"price": 200000,
"acquisition_costs": 18000,
"land_value": 40000 # 20% of price
}
}
property_investment = SpanishRentalProperty(property_data=sample_property, owner_data={})
# Use the new method to get the final gain
property_investment.calculate_capital_gain(
sale_price=280000,
transmission_costs=19000,
holding_period_years=6,
total_improvement_costs=12000
)
Test your understanding!
An investor sells a property for €500,000. The selling costs (agency commission, plusvalía) total €30,000. The adjusted acquisition cost (valor de adquisición), which you calculated separately, is €350,000. Is the capital gain €150,000?
Show answer
No. The capital gain is not based on the raw sale price. It's based on the valor de transmisión.
- Valor de Transmisión: €500,000 (Sale Price) - €30,000 (Selling Costs) = €470,000.
- Ganancia Patrimonial: €470,000 (Valor de Transmisión) - €350,000 (Valor de Adquisición) = €120,000.
The €30,000 in selling costs directly reduces the taxable gain.
Conclusion
You have now mastered the complete calculation for determining the taxable capital gain on a Spanish property sale.
Key Takeaways:
- The capital gain is the difference between the transmission value and the adjusted acquisition value.
- The transmission value is the sale price minus all inherent selling costs, like agency fees and the
plusvalía municipaltax. - Deducting these selling costs is crucial as it directly reduces your taxable profit.
- For properties acquired before 1995, a special transitional regime may apply, offering a significant reduction on the portion of the gain generated before 2006.
Preview of the Next Lesson:
We've successfully calculated the taxable base (€62,392 in our example). The next logical step is to determine the actual tax bill. In the next lesson, you will learn to calculate the IRPF capital gains tax liability for property sales in Spain by applying the progressive tax rates for savings income (base imponible del ahorro).