Capital gains when selling: how they are calculated and filed
When you sell fund units, shares or an ETF, what is taxed is not what you receive but the capital gain or loss: the difference between what you get and what the units you sold cost you. Simple enough, until you have bought on several dates at several prices. That is where the rules on this page come in.
Transfer value minus acquisition value
- Acquisition value: what you paid for the units you sold plus the purchase fees and costs.
- Transfer value: what you receive for the sale minus the sale fees and costs.
- Gain (or loss) = transfer − acquisition.
Fees count on both sides: they raise the cost and lower the proceeds, so they reduce the gain. If a purchase of 100 units had a €10 fee and you sell 40, €4 of it belongs to those 40.
FIFO: the oldest units always go first
For homogeneous securities (shares of the same company, units of the same fund or ETF) Spanish law requires FIFO (first in, first out): you are deemed to sell the units you bought first. You cannot pick the most expensive lot to pay less, nor use the average price.
An often-missed detail: FIFO applies to all your units of that security, whichever broker holds them. If you bought an ETF with one broker in 2020 and the same ETF with another in 2023, and you sell with the second, the 2020 units go first for tax purposes. How many units each broker holds does not change; the cost used to work out the gain does.
Offsetting: losses subtract
The gains and losses of all your sales in the same year are added together. If in one year you gain €3,000 selling a fund and lose €1,000 selling some shares, you are taxed on €2,000.
If the year ends negative:
- That negative balance can offset up to 25% of the positive balance of interest and dividends in the same year.
- Whatever remains is carried forward for four years to offset future gains.
A positive balance is taxed in the savings base in bands: 19% up to €6,000, 21% up to €50,000, 23% up to €200,000, 27% up to €300,000 and 30% above that.
The two-month rule
If you sell at a loss and buy units of the same security within the two months before or after (listed securities), that loss cannot be offset yet: it is recognised when you sell the repurchased units. The rule targets selling at a loss just to save tax and buying back the next day.
Sales in another currency
If the security trades in dollars (or another currency), the Spanish tax authority asks for two separate calculations (DGT binding ruling V0152-26):
- The gain on the shares is calculated in dollars (sale minus purchase) and that difference is converted to euros at the exchange rate of the sale date.
- The exchange difference on the dollars invested is a separate gain or loss: what they cost you in euros when you bought versus what they are worth in euros when you sell.
If your broker converts to euros when you buy and when you sell, both together add up to converting the purchase at its date's rate and the sale at its own. That is why you can gain in dollars and lose in euros (or vice versa) if the dollar has moved. If you keep the dollars in an account, the exchange difference is not declared until you convert them.
Investment funds: switching
Between Spanish-registered investment funds you can move money from one to another with a switch (traspaso) without paying tax: the gain is deferred until you really sell. ETFs generally cannot be switched: selling one to buy another is a sale.
Sextante's capital gains report
If you record your purchases and sales in the portfolio, the Tax return tab (in the portfolio header) prepares the year's summary for you:
- It matches each sale against its purchases with FIFO per security, across all your brokers, with purchase fees spread across the units.
- It nets gains and losses within the tax year and estimates the tax with the savings scale.
- It converts sales in other currencies to euros at the ECB reference rate of the sale date and works out the exchange difference separately, as explained above.
- It lets you download a CSV with one row per sale (date, transfer value, acquisition value and gain, in the currency and in euros), which is the detail the tax return asks for.
What it does not do, and you should check yourself: carrying forward losses from previous years, the 25% offset against dividends and interest and the two-month rule.
Educational information, not tax advice. Rules change; check your case with the Spanish tax agency (AEAT) or an adviser before filing.