When tax applies: the general rule
In Spain, as a general rule, gains from savings and investment (interest on accounts and deposits, dividends, and gains from selling funds or shares) are declared under the savings tax base of personal income tax, with a progressive bracket system. This means the higher the gain, the higher the percentage applied to the portion above each bracket.
The exact brackets and their percentages change from year to year, and can vary slightly in certain regions with their own tax regimes (the Basque Country and Navarre have their own rules). That's why this is discussed here in general, approximate terms, not as a definitive tax table.
Investment funds: the transfer advantage
One of the most relevant aspects for anyone investing in funds in Spain is the so-called "transfer regime": if you move your money from one fund to another without redeeming it (without withdrawing it to your bank account), it isn't considered a sale for tax purposes, and therefore isn't taxed at that point. Tax is only paid when you finally redeem the money.
This advantage is one of the reasons index funds are a popular vehicle for benefiting from compound interest in Spain: it allows you to reorganize your investment without "breaking" the constant reinvestment effect that makes capital grow.
Savings accounts and deposits
Interest from savings accounts and deposits is also taxed under the savings base, but unlike funds, there's no equivalent transfer regime: interest earned is considered income for the year it's paid, regardless of whether you withdraw it or leave it in the account.
Pension plans: a different treatment
Pension plans have their own tax advantages when contributing (within certain annual limits), but are taxed differently when withdrawn, as employment income under the general tax base, not the savings base. This makes them fiscally different from a regular investment fund, and it's worth understanding that difference before deciding where to save long-term.
Why this matters for your compound interest calculation
A compound interest calculator, like the one on this site, normally shows the gross result, before taxes. The net capital you'd actually have available, after paying taxes upon redemption, will be somewhat lower than the calculated gross figure. Keeping this in mind helps avoid overestimating the final result when planning a savings goal.