PERSONAL greed is often the explanation given for the disastrous forays of the world's banks into America's subprime mortgages. In Germany, however, many of the worst decisions were made not by the bonus-driven crowd in Frankfurt but by ostensibly well-intentioned public servants in the country's public banks, or Landesbanken.

The extent of the damage wrought on the Landesbanken, most of which are owned by state governments and local savings banks, was revealed late last month in a leaked document that was published by the Süddeutsche Zeitung, a newspaper. It said that the financial regulator, BaFin, reckoned that German banks—mostly Landesbanken—held €816 billion ($1.1 trillion) in toxic securities. On May 6th five Landesbanken had their ratings cut by Standard & Poor's.

So deeply in debt are the hardest-hit of this unwieldy bunch that only the central government has the cash to prop them up. Yet instead of lamenting, many in Berlin see this as the first opportunity in decades to fix a banking system that is plagued by fragmentation and poor profitability. The main problem facing German banks is that there are too many of them. The country has more than twice as many banks relative to its population as countries such as Britain, Canada and Japan, according to the IMF (see chart). The intense competition for customers means that they are far less profitable in Germany than in the rest of Europe, according to Moody's, a rating agency.

In an open market, profitable banks would solve this problem by swallowing their weaker rivals. Yet in Germany this has not happened because state governments have blocked takeovers of public banks and many savings banks have also been protected by law.

Government guarantees are also to blame. Until 2005 the debts of Landesbanken were backed by state governments. This allowed the public banks to borrow and lend more cheaply than privately owned institutions. New guarantees have since been banned, but before the prohibition came into force, Landesbanken were allowed to load up with debt (the debt does not mature until 2015). Moody's reckons that they still have as much as €300 billion of guaranteed loans on their books. Much of this was used to fund subprime securities.

The weaknesses in Germany's banking system have long been a worry for the federal government. In talks with the IMF last year both sides agreed that the country's fragmented banking system posed huge risks. Yet most of the government's efforts to get Landesbanken to merge have been stymied by the states, which have proved reluctant to lose control of their wards.

Now change may finally be forced on the Landesbanken by adversity. The central government controls the purse strings of a federal bail-out fund, and it is understood to have made consolidation a condition for offering help with toxic assets. People familiar with the plan expect the number of Landesbanken to shrink to between two and three, from seven now.

Consolidation of these public banks would be a useful first step, but better still would be the tougher job of privatising them and of merging the country's savings banks. Germany should also take a hard look at how its pre-2005 guarantees of public banks encouraged them to behave recklessly. The lessons it learns may prove useful to governments around the world that are now having to stand behind the debts of their banks to stop them from collapsing, while at the same time desperately trying not to sow the seeds of the next financial crisis.