Skip to main content

Someone wanted to learn this too, so Grasp built them a personal learning path.

You can keep exploring this one or create your own

Spanish Property Capital Gains Tax

Hello! Welcome to the next lesson in our module on the taxation of Spanish real estate sales.

In our previous session, we assembled the complete formula to determine the taxable profit from a property sale, the Ganancia Patrimonial. We calculated it as the Valor de Transmisión minus the Valor de Adquisición, arriving at a taxable gain of €62,392 in our running example.

Today, we will answer the final question: what is the actual tax bill? The learning outcome for this lesson is to calculate the IRPF capital gains tax liability for property sales in Spain. We will apply Spain's progressive tax rates to the capital gain we've already calculated and translate that taxable base into a final tax liability.

1. The 'Base Imponible del Ahorro'

In the Spanish personal income tax system (IRPF), not all income is treated equally. Income is channeled into two main "baskets," each with its own set of tax rates:

  1. Base Imponible General (General Tax Base): This includes income from work (salaries), business activities, and rental income. It is taxed at progressive rates that are generally higher.
  2. Base Imponible del Ahorro (Savings Tax Base): This includes returns on capital, such as interest, dividends, and, most importantly for us, capital gains (ganancias patrimoniales) from the sale of assets like property.

Therefore, the Ganancia Patrimonial we calculated is added to your savings tax base and taxed according to a separate, more favorable set of progressive rates.

The video below, which you may recall from our previous lesson, provides a great walkthrough of declaring a property sale. Pay close attention to how the calculated gain flows into the savings tax base to determine the final tax.

“Así se calcula la GANANCIA PATRIMONIAL en Hacienda (PASO A PASO REAL)” 🏚️

Let's watch this segment from the video “Así se calcula la GANANCIA PATRIMONIAL en Hacienda”. The presenter simulates a €100,000 gain and shows how the tax software automatically applies the savings tax rates to calculate the final IRPF liability.

Watch from 04:55 to 06:05. The key takeaway is hearing the phrase 'tributaría en la renta con los tipos impositivos de la base imponible del ahorro' and seeing the final tax amount generated.

2. IRPF Tax Brackets for the Savings Base

The savings tax base is subject to a progressive system. The tax is calculated in tranches, meaning you pay a different rate on different portions of your gain.

Here is a table of the IRPF savings tax brackets applicable in Spain.

Comparative Table of Spanish Savings Income Tax Brackets (Before and After Reform)
This table shows the progressive tax brackets for the 'Base Liquidable del Ahorro' (Savings Tax Base) in Spain. For our calculations, we will use the rates applicable up to 2024.

Based on the table, the rates are as follows:

Capital Gain Bracket (Ganancia Patrimonial) Tax Rate
Up to €6,000 19%
From €6,000.01 to €50,000 21%
From €50,000.01 to €200,000 23%
From €200,000.01 to €300,000 27%
Above €300,000 28%

(Note: As the image indicates, tax rates are subject to change. The highest bracket, for instance, is scheduled to increase.)

3. Calculating the IRPF Tax Liability

To calculate the tax, you apply these rates sequentially to your total capital gain. This is best understood with an example.

First, let's review a very clear, step-by-step written example of this calculation.

Capital Gains Tax in Spain: How Much Will You Pay When ...

The following article, 'Capital Gains Tax in Spain', contains an excellent, straightforward example of calculating the tax liability for a resident. Please review this specific part of the article.

Read the section titled 'Example: Resident vs Non-Resident'. Focus only on the 'Spanish Resident' calculation, which breaks down the tax on an €80,000 gain bracket by bracket.

Now, let's apply the same methodology to our running example, where the Ganancia Patrimonial was €62,392.

  1. First Bracket (up to €6,000):

    • Tax = €6,000 × 19% = €1,140
  2. Second Bracket (€6,000.01 to €50,000):

    • The amount of gain in this bracket is €50,000 - €6,000 = €44,000.
    • Tax = €44,000 × 21% = €9,240
  3. Third Bracket (€50,000.01 to €200,000):

    • The remaining gain falls into this bracket: €62,392 - €50,000 = €12,392.
    • Tax = €12,392 × 23% = €2,850.16
  4. Total Tax Liability:

    • Total IRPF = €1,140 + €9,240 + €2,850.16 = €13,230.16

So, a capital gain of €62,392 results in a total IRPF tax liability of €13,230.16.

Test your understanding!

An investor realizes a capital gain of €45,000 from a property sale. How would you calculate the IRPF tax liability? Is it simply €45,000 * 21%?

Show answer

No, you must apply the brackets progressively.

  1. The first €6,000 is taxed at 19%: €6,000 * 0.19 = €1,140.
  2. The remaining amount (€45,000 - €6,000 = €39,000) is taxed at 21%: €39,000 * 0.21 = €8,190.
  3. Total tax liability: €1,140 + €8,190 = €9,330.

Calculating it as €45,000 * 21% (€9,450) would be incorrect and result in overpaying tax.

4. Updating Our Python Model

Let's extend our SpanishRentalProperty class to automate this tax calculation. We will add a method that takes the capital gain as input and returns the IRPF tax liability. Given your background, implementing this progressive calculation logic should be very familiar.

# Continuing from the previous lesson's SpanishRentalProperty class

class SpanishRentalProperty:
    # ... (all previous methods: __init__, calculate_adjusted_acquisition_cost, calculate_capital_gain)
    
    # ... 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.
        """
        valor_de_transmision = sale_price - transmission_costs
        valor_de_adquisicion = self.calculate_adjusted_acquisition_cost(
            holding_period_years=holding_period_years,
            total_improvement_costs=total_improvement_costs
        )
        capital_gain = valor_de_transmision - valor_de_adquisicion
        return capital_gain
    
    def calculate_irpf_liability(self, capital_gain: float) -> float:
        """
        Calculates the IRPF tax liability on a given capital gain
        based on the Spanish savings tax base brackets.
        """
        if capital_gain <= 0:
            return 0.0

        tax = 0.0
        remaining_gain = capital_gain

        # Bracket 1: up to 6,000 EUR at 19%
        if remaining_gain > 0:
            taxable_in_bracket = min(remaining_gain, 6000)
            tax += taxable_in_bracket * 0.19
            remaining_gain -= taxable_in_bracket

        # Bracket 2: 6,000.01 to 50,000 EUR at 21%
        if remaining_gain > 0:
            taxable_in_bracket = min(remaining_gain, 50000 - 6000)
            tax += taxable_in_bracket * 0.21
            remaining_gain -= taxable_in_bracket

        # Bracket 3: 50,000.01 to 200,000 EUR at 23%
        if remaining_gain > 0:
            taxable_in_bracket = min(remaining_gain, 200000 - 50000)
            tax += taxable_in_bracket * 0.23
            remaining_gain -= taxable_in_bracket

        # Bracket 4: 200,000.01 to 300,000 EUR at 27%
        if remaining_gain > 0:
            taxable_in_bracket = min(remaining_gain, 300000 - 200000)
            tax += taxable_in_bracket * 0.27
            remaining_gain -= taxable_in_bracket

        # Bracket 5: above 300,000 EUR at 28%
        if remaining_gain > 0:
            tax += remaining_gain * 0.28

        return tax

# --- Example Usage ---
if __name__ == '__main__':
    # Using the same data as our manual example
    gain_from_previous_lesson = 62392.00
    
    # We can instantiate the class, but for this specific calculation,
    # we can also call the method directly if we have the gain.
    # Here, we'll create an instance for completeness.
    property_investment = SpanishRentalProperty(property_data={}, owner_data={})

    irpf_tax = property_investment.calculate_irpf_liability(gain_from_previous_lesson)

    print(f"--- IRPF Liability Calculation ---")
    print(f"{'Capital Gain':<25}: €{gain_from_previous_lesson:,.2f}")
    print(f"{'Total IRPF Tax Liability':<25}: €{irpf_tax:,.2f}")

Running this code produces the output:

--- IRPF Liability Calculation ---
Capital Gain               : €62,392.00
Total IRPF Tax Liability   : €13,230.16

This confirms our manual calculation and provides a reusable tool for future analyses.

5. Key Exemptions for Tax Planning

Calculating the tax is one thing; legally minimizing it is another. Spanish tax law provides several powerful exemptions, particularly concerning the sale of a primary residence. Being aware of these is critical for any serious investor.

Cuidado al VENDER tu CASA | Estos son los IMPUESTOS a Pagar

The following video by Pau Antó provides an excellent summary of the three main legal exemptions from paying IRPF on a property sale. This is essential practical knowledge.

Watch the segment from 03:04 to 04:50. The speaker clearly outlines the exemptions for reinvestment, for sellers over 65, and for investing in an annuity.

To summarize the key points from the video:

  • Reinvestment in a Habitual Residence (Reinversión en Vivienda Habitual): If you sell your main home (vivienda habitual) and reinvest the full proceeds into a new main home within two years (before or after the sale), the capital gain is fully exempt from IRPF.
  • Exemption for those Over 65: If you are over 65 years old and sell your main home, the capital gain is completely exempt, with no requirement to reinvest the money.
  • Exemption via Annuity (Renta Vitalicia): If you are over 65 and sell any property (not just your main home), you can be exempt from the capital gains tax if you use the proceeds (up to a limit of €240,000) to constitute a life annuity with an insurance company within six months.

These rules are powerful but have strict requirements. Planning a sale with these exemptions in mind can make a substantial difference to your net returns.

Conclusion

Congratulations! You can now calculate the complete IRPF tax liability on a Spanish property sale, from the initial transaction figures down to the final tax bill.

Key Takeaways:

  • Capital gains from property sales are taxed under the base imponible del ahorro.
  • This savings base has progressive tax brackets (19%, 21%, 23%, etc.), which must be applied sequentially to the total gain.
  • Our Python model can now automate this tiered calculation, providing a precise tax liability figure.
  • Crucial tax exemptions exist, primarily for the sale of a primary residence and for sellers over 65, which are key tools for tax planning.

Preview of the Next Lesson:
The IRPF is the national-level tax on your profit. However, there is one more tax to consider when selling property in Spain: the plusvalía municipal. This is a local tax levied by the town hall on the increase in the value of the land the property sits on. In our next lesson, we will learn how to calculate the plusvalía municipal, which will complete our understanding of the taxes involved in a property disposition.

Can't find a good explanation? Sign up and we'll make it for you

Sign up