The European Commission opened in-depth investigations on Wednesday to determine if billions of euros in German government assistance to two banks, hit by the U.S. sub-prime market crisis, amounted to illegal state aid.

The European Union's executive arm will decide whether state loans and guarantees granted to corporate lender IKB and state-backed regional bank SachsenLB were made under normal capital market conditions.

If not, the aid would be considered illegal and must be paid back to the German government.

IKB, which has lent to many of Germany's top firms, is on its third bailout after its state owners hammered out another rescue earlier this month.

A spokesman for the German Finance Ministry in Berlin left the door open to even more aid.

We don't rule that out, how could we?, spokesman Torsten Albig said when asked at a regular government news conference whether Germany excluded the possibility of further aid.

The Commission said state-owned bank Kreditanstalt für Wiederaufbau provided a risk shield of around 9 billion euros ($13.5 billion) to IKB and the government of the German state of Saxony and state-owned banks clubbed together to grant liquidity assistance of around 17 billion euros to SachsenLB.

Without these and several subsequent measures the banks would not have been able to continue their business, the Commission said in a statement.

The Commission has to assess whether these measures constitute state aid and, if so, whether they can be found compatible with EU rules for rescuing and restructuring firms in difficulties, it said.

Sachsen LB racked up about 30 billion euros of shaky investments in subprime mortgages and other structured debt. It has been sold to rival LBBW.

Under EU rules, public support can be provided to prevent companies from going bust in some circumstances, but state aid that distorts competition is prohibited.

The European Commission said last year it was seeking more details about Germany's aid to banks.

In December, German Finance Minister Peer Steinbrueck said he did not think cash set aside by KfW to help IKB fell foul of the EU rules. (Reporting by David Lawsky and Jan Strupczweski; Editing by William Schomberg/Elaine Hardcastle)