A capital gain is the positive difference between what you receive when selling an asset and what it cost you to buy it. It is the other half of an investor's return — the part that is not dividends — and it has its own tax mechanics for Spanish residents.
Capital gain = Sale value − Acquisition value (fees and commissions included)Capital gains go into the savings base of the IRPF, on a progressive scale starting at 19% (exact brackets change; the updated detail is in our tax guide). The most valuable nuance: they are only taxed when you sell. While you hold, the accumulated gain generates no tax at all — the deferral that makes buy & hold and accumulating ETFs so efficient.
Both are taxed in the savings base, but with a difference in control: the dividend is taxed when the company decides to pay it; the capital gain, when you decide to sell. That asymmetry underlies many portfolio decisions — and is why combining both sources gives tax flexibility.
It is taxed in the IRPF savings base, on a progressive scale starting at 19% and rising by brackets according to your total savings income for the year. You only pay when you sell, never on unrealised appreciation.
Yes: losses offset gains from the same year, the excess offsets up to 25% of your investment income, and the remainder carries forward 4 years. That is the reason to review losing positions before the tax year ends.
An anti-abuse rule: if you sell at a loss and rebuy the same security within two months (before or after), you cannot deduct that loss until you sell for good. It prevents manufacturing tax losses without unwinding the investment.