All investments are taxed at a flat rate of 18% which is automatically withheld by the payee for all residents accounts. If you are a resident you must advise your bank so that they can withhold the 18%.
Needless to say many people have not declared this to their bank to avoid paying the 18% but the rules have now been changed so that this tax avoidance cannot take place any longer.
All banks reports all accounts whether saving or loans to Spanish tax man for the annual tax return system during June/July of each year.