Essential Points
- Any profit from selling shares in Spain goes into the savings base of the IRPF (Personal Income Tax) and is taxed between 19% and 28%, not at the marginal rate of your salary.
- You can offset losses with profits from the year, and even with dividends within certain limits, to reduce what you pay.
- There is a little-known rule, the two-month rule, which can invalidate a loss for tax purposes if you repurchase the same security too soon.
- The time frame varies depending on the asset —two months for stocks and ETFs, one year for non-listed funds— and looks both forward and backward.
Every spring, when tax season opens, thousands of investors in Spain ask themselves the same question: how much will it cost me in taxes for selling my shares? And there's a second, more unspoken question, asked only by those who have already been shocked: why won't the Tax Agency let me offset a loss I thought was a sure thing? Unlike salaries, which are taxed under the general income tax brackets according to your income level, stock market gains follow their own rules within the Personal Income Tax (IRPF), with tax brackets, deadlines, and an anti-avoidance rule—the two-month rule—that surprises those who aren't aware of it in time.
In this article, we bring together the two sides of stock taxation in Spain: first, the savings basis, the calculation of gains and losses, the current tax brackets, and the offsetting of losses; then, in depth, the two-month rule of article 33.5 of the Spanish Personal Income Tax Law (LIRPF), its exact deadlines according to the type of asset, the most costly mistakes investors make, and how to plan a sale at a loss so that it actually counts in your tax return.
What is the basis of savings and why is it key for the investor?
Spanish income tax (IRPF) divides each taxpayer's income into two main categories: the general tax base and the savings tax base. The general tax base includes salary, income from business activities, and rental income, and is taxed according to a progressive scale that can exceed 45% in the highest brackets. The savings tax base, on the other hand, includes capital gains and losses from the sale of assets such as stocks, funds, or real estate, along with income from movable capital: dividends and interest from products such as savings accounts or bonds.
For those who invest in stocks, this is good news in terms of simplicity. All your profits from selling stocks are taxed under your savings income, regardless of your overall income level, and are taxed at the fixed and progressive rates we'll discuss below, not at the marginal rate that would apply to your salary. This is a nuance that surprises many first-time investors, who mistakenly assume that their profits will be taxed at the same rate as their salary.
How are capital gains and losses calculated? The FIFO method
Calculating a capital gain or loss on shares is based on a simple formula: subtract the purchase price and any deductible expenses associated with both transactions, such as brokerage fees or stock exchange fees, from the sale price. If the result is positive, there is a capital gain; if it is negative, there is a loss. Imagine you buy shares for €10 and sell them for €15, paying €10 in commissions for the entire transaction: your net profit will not simply be €5 per share, but rather the result of subtracting those commissions from the total gross profit. This is a hypothetical example for illustrative purposes: actual results depend on each taxpayer's tax situation.
When you have multiple purchases of the same stock at different times and prices, the Spanish Tax Agency (Hacienda) doesn't allow you to choose which batch to sell first. Spanish regulations require the FIFO method—first in, first out—for homogeneous shares: it's understood that you sell the ones you bought the longest time ago first, not the most recent ones.
This detail has significant practical consequences, and not just for calculating the result of a sale: as we'll see later, it also determines which purchases count as "repurchases" for the purposes of the two-month rule. Keeping an organized record of your transactions, with the date and price of each purchase, is the only way to accurately anticipate your taxable income before selling.

Does it matter how long you've held the shares?
One of the most common misconceptions among experienced investors is the belief that there's a different tax rate depending on how long the shares were held before being sold. This distinction existed in Spain, but it disappeared with the 2015 tax reform: before then, gains generated in less than a year were taxed differently than those accumulated over a longer period.
Under current regulations, that difference no longer exists. All capital gains from the sale of shares are included in savings income and taxed according to the same progressive tax brackets, regardless of whether the shares were held for one week or ten years. The holding period remains relevant for other matters, such as the FIFO accounting method or the two-month rule, which we will discuss later, but it does not determine a different tax rate.
It's worth emphasizing this point because the historical misunderstanding persists. If you sell shares you've held for years, don't expect a tax break based on age: your profit will be taxed exactly the same as if you had bought and sold those same shares in the same month.
Offsetting losses with gains: how it works and its limits
Not all stock market transactions are successful, and the Spanish Personal Income Tax (IRPF) includes mechanisms to prevent losses from being completely lost for tax purposes. Within the same tax year, capital gains and losses from the sale of shares are directly offset against each other: if in one year you have €1.000 in losses and €800 in gains, you pay tax on €0 and have €200 of losses carried forward to future years.
There is also a cross-off between two categories of the savings base: if after offsetting your losses with your own capital gains there is a negative balance, you can use it to reduce the income from movable capital for the year, such as dividends or interest, with a limit of 25% of said income according to the 2025 regulations.
If, after both offsets, a loss remains unabsorbed, you can carry it forward and offset it against profits in the following four tax years. This isn't an automatic mechanism applied by the tax authorities: you must declare it in each subsequent tax return to avoid losing this right. And this is precisely where the rule we'll see next comes into play, because not all losses that you would offset in this way are immediately taxable.
The two-month rule: the anti-application rule for losses under Article 33.5 of the Personal Income Tax Law
Of all the rules affecting the taxation of shares, the two-month rule is probably the least known and the one that causes the most surprises in tax returns. It is set out in Article 33.5 of the Personal Income Tax Law, where it is technically called the "anti-loss carryforward rule," and its objective is to prevent an investor from realizing a tax loss without actually changing their market position.
The mechanism works like this: if you sell securities at a loss and, within a certain period before or after that sale, you repurchase identical securities—from the same issuer and with the same rights—that loss is not tax-deductible at the time of the sale. It doesn't disappear, but it's "parked" until you definitively sell the repurchased shares, without having repurchased them again within the specified period; only then can you claim it.
It's important to avoid any alarmist tone surrounding this rule. It's not a penalty, nor does it mean permanently losing the right to that loss, and it doesn't prohibit repurchasing: the tax authorities designed it to prevent selling an asset just as it's trading below its purchase price and then buying it back almost immediately without changing the actual market exposure at all. If you still hold the same investment in practice, the law considers that your financial situation hasn't changed enough to warrant recognizing that loss yet.
Listed vs. unlisted: the exact deadlines
The two-month rule period is not uniform: it depends on whether the asset is traded on an organized market or not. For listed securities, such as common stocks or ETFs, the period is two months before or after the sale at a loss. For unlisted securities, such as units in traditional investment funds, the period is extended to one year before or after the same sale.
This "before or after" nuance is what most surprises those encountering the rule for the first time: the timeframe doesn't begin at the moment of the sale and doesn't only look forward, it also looks backward. If you bought shares of a company weeks ago and now sell other shares of that same company at a loss, the rule can still be triggered, even though the buyback, strictly speaking, never actually takes place after the sale.
And what about ETFs? The most confusing nuance
ETFs are subject to the short-term, two-month period, not the one-year period. The reason is that ETFs are traded on organized markets, just like stocks, and are treated as listed securities for tax purposes, not as traditional investment funds, even though they have an underlying fund structure. Unlisted funds, on the other hand, benefit from the tax-free transfer regime of Article 94 of the Spanish Personal Income Tax Law (LIRPF): you can move your money from one fund to another without triggering taxable income until the final redemption. ETFs do not have this privilege, precisely because they are traded like stocks.
An ETF thus combines the best and worst of both worlds: it has the shorter holding period of the two-month rule, useful if you want to recover your position quickly, but without the tax deferral of transferring between funds. If you trade with non-exchange-listed accumulating index funds, the applicable holding period becomes the longer one, of one year.
What are “homogeneous values”?
The other key concept is that of “homogeneous securities.” The law considers homogeneous those assets that represent substantially the same thing: the same company, the same ISIN, the same fund. If you buy a different asset, even if it belongs to the same sector or a direct competitor, the anti-application rule does not apply because there is no homogeneity between what was sold and what was purchased.
The most common question arises with ETFs that track the same index but are managed by different companies. If the ISIN and the underlying asset are truly different, the rule shouldn't apply in principle. However, when the products are virtually identical, there's a gray area that should be discussed with a tax advisor before proceeding.
A practical example: when buying back is expensive
Let's look at a numerical example. An investor owns 500 shares of company X, purchased at €20 per share (total cost of €10.000). In November, they sell them at €15, incurring a loss of €2.500. Three weeks later, they buy back the exact same shares at €15,50, believing they have now "closed" the loss.
The tax outcome is that the Tax Agency does not allow the €2.500 to be offset in that tax return because the repurchase occurred within the two-month period. The loss is not lost, but it is deferred until the investor definitively sells the new shares without repurchasing them within the deadline. If the investor had €2.500 in capital gains from other transactions that they wanted to offset that same year, they will continue to be taxed on them at the applicable rate under the savings income tax bracket, without being able to reduce their tax bill with the loss they expected to have available. For unlisted securities, remember that the equivalent period is not two months but one year before or after the sale.
How to declare shares on your tax return? Form 198, Form 100, and foreign brokers
Declaring stock market transactions on your income tax return (IRPF) doesn't usually require complex manual calculations, thanks to the reporting obligations of financial intermediaries. Brokers and platforms operating in Spain are required to report their clients' transactions to the Tax Agency (AEAT) using form 198, so many of your transactions will already be reflected in the draft tax return that the AEAT provides each year.
Even so, it's advisable to review before confirming the declaration: check that all your transactions are included, paying special attention if you have traded with foreign brokers who don't always report as quickly as domestic ones; verify that the amounts match your records, including any losses deferred by the two-month rule that are already computable this year; and if you detect discrepancies, manually complete the capital gains and losses boxes on form 100.
The exact fields in form 100 can vary from year to year, so it's best to consult the official AEAT guide for the year you're filing. Keeping an organized record—dates, prices, fees—greatly simplifies this process, whether you do it yourself or use an accountant.



Author


