* Spain's banks to receive aid over 18 months, from July
* 12.5 years average maturity and 3-4 pct interest on loans
* All Spanish banks to increase core tier one to 9 pct
* Savings banks to lose control of commercial lenders
By Robin Emmott and Matthias Sobolewski
BRUSSELS/BERLIN, July 10 (Reuters) - A euro zone bailout for Spain's crippled banks paves the way to clean up the financial sector within 18 months and will also put the economy on a path to recovery, Spain said on Tuesday.
Euro zone finance ministers agreed on Monday a rescue package of up to 100 billion euros ($123 billion) for Spanish banks devastated by a burst housing bubble.
"This puts us in a position to clean up the Spanish financial system that I think is going to go very deep," Economy Minister Luis de Guindos said after the meeting in Brussels, where ministers approved the deal and will sign off on it on July 20.
"We must make maximum use of the next 18 months to do this clean up ... and bring down debt levels in the Spanish economy," he told a news conference.
Following the formal signing of the deal, Madrid expects 30 billion euros in a first tranche of money that will be available immediately for state-rescued banks that urgently need funds.
That will make Spain the fourth euro zone nation to receive emergency aid in a debt crisis that started in Greece and has spread across the bloc.
De Guindos said Finland was the only euro zone country that has asked for collateral on the loans to Spain, which will be first provided by the bloc's temporary rescue fund, the European Financial Stability Facility (EFSF).
The loans will have an average maturity of 12.5 years and a maximum of 15 years, with interest rates of between 3 percent and 4 percent, de Guindos said.
Once the permanent European Stability Mechanism (ESM) is operational some time over the European summer, it will take over the job of funding Spain's programme.
Under the terms of the bank bailout's draft memorandum of understanding (MoU), which was seen by Reuters, 14 banking groups that make up about 90 percent of the banking system will be tested for their recapitalisation needs in a review due to be completed by the second half of September.
"Right now, consultants are looking at all the portfolios and then comes the stress test," de Guindos said.
"There will be banks who come out fine, others who will have until March to raise capital and others who will immediately ask for a capital injection," he said.
All Spain's banks will have to increase their core capital ratios to 9 percent by the end of 2012 and keep them at this level until the end of 2014. However, the government will review by December the requirements for setting aside capital to cover losses on real estate assets.
There will be a special focus on savings banks, or "cajas", which had close links with local governments and were responsible for much of the unsustainable lending over the last decade, and their governance structure will be reviewed.
According to the MoU, Spanish authorities will prepare by the end of November a new law to reduce the stakes that savings banks have in commercial lenders to non-controlling levels. Banks that are controlled by the cajas and receive state aid would be become listed companies.
The measure is mostly symbolic, applying only to a handful of banks representing a small share of Spain's banking system, but a failure to implement it could worry investors.
The document also says that holders of hybrid capital and subordinated debt in state-rescued banks will have to take a haircut on their investments in order to minimise the cost to taxpayers of the restructuring.
Hundreds of thousands of small shareholders who bought instruments such as preference shares are likely to be affected.
The first injection of capital into banks not already rescued by the state and unable to raise capital by themselves can be expected by October, after reviews by the Spanish government and the European Commission.
De Guindos said he hoped some of the bank aid could be given directly to banks, rather than through the Spanish government, once an ECB-led supervisor for euro zone banks is operational, some time during next year.
"The issue of a direct recapitalisation is open, because in the memorandum, there will be a reference to the (euro zone leaders' June 28/29) summit conclusions where it was established that with a single banking supervisor, direct recapitalisation will be possible," he said.
Spain wants to avoid the bailout money adding permanently to its debt and deficit load because that could push the country towards a sovereign bailout.