Spain is back in the headlines, threatening to drag down the global economy. The panic started last week, after the country’s fourth-largest bank, Bankia, announced that it needed $23.5 billion in aid. But how did Spain get to this point? Here’s our explainer on the crisis:

Yikes. (Daniel Ochoa de Olza/AP)

Not exactly. Before the financial crisis hit, Spain was actually running smaller deficits than even Germany. Its public debt was just 27 percent of GDP. Spain was considered a model of fiscal responsibility.

Then how did Spain get into its current mess?

It all started with a housing bubble. During the 2000s, thanks to low interest rates and an influx of foreign capital, Spain had a furious boom in housing construction — houses that, it turned out, the country didn’t really need. Below is a graph of the price-to-rent index in Spain, which gives a sense of the sheer size of the bubble. In 2007, the bubble finally burst. And Spain still isn’t anywhere close to recovering. Economists Cinzia Alcidi and Daniel Gros have estimated that housing prices have fallen 26 percent, but that’s still only about half of the total decline that will ultimately need to happen:

Why does it matter if Spain’s housing prices fall? Cheap houses for everyone!

Well, it’s a big problem for all those Spanish banks that are holding mortgages or properties. Ultimately, Alcidi and Gros estimate that the excess housing in Spain amounts to about $470.1 billion, or 37 percent of the country’s GDP. “It goes without saying that our estimated total,” they note, “exceeds by far the provisions and write downs accumulated by the Spanish banking system … so far.” In other words, Spanish banks have taken big losses already, and they’re likely to take even bigger losses in the years ahead — up to $320 billion, according to the Institute of International Finance.

So that’s why Bankia’s in trouble?

Yep. During the housing bubble, it was Spain’s regional banks, or cajas, that threw the most money at property developers. The entity that’s getting all the headlines now, Bankia, was formed after a 2010 merger of seven cajas that were too weak to stand on their own. But after receiving $5.6 billion in government aid earlier this month, Bankia recently announced that it actually needed about $23.5 billion in aid. And the housing bubble hasn’t even finished bursting yet.

Okay, Spain just has to give Bankia a $23.5 billion bailout. What’s the problem with that?

Spain doesn’t have that sort of cash readily lying around. Investors are already nervous about lending more money to Spain, whose deficits have spiked ever since its housing market collapsed. And Spain’s economy is now in shambles. Before the crisis, one-seventh of its workers were employed in the housing sector. Since the bubble popped, unemployment has soared to 25 percent. The retail sector has collapsed. Even the country’s once-bright export and auto sectors have started sinking in recent months.

And, to pile on, Spain is supposed to reduce its deficit from 8.9 percent of GDP to 3 percent of GDP next year, in order to follow euro zone rules — and all that austerity is squeezing the economy further.

How does Spain get its economy growing again without its banks?

That’s the problem. Spain can’t really grow if its banks aren’t lending to businesses. And its banks aren’t lending to small and medium-sized businesses, because they’re facing massive losses and shrinking balance sheets. Plus, plenty of Spanish depositors are taking their euros out of Spanish banks and sending them to Germany because they’re afraid that Spain might leave the euro. That’s made Spain’s bank problems even worse.

This sounds like a serious bind.

Yep. It’s partly why Tyler Cowen says Spain might be “in a self-cannibalizing downward spiral.” (He offers up a lot more reasons at the link.)

Is there any other way Spain can save its banks?

The government also is trying to get creative in propping up Bankia. Matthew O’Brien of The Atlantic explains the latest scheme: “They proposed recapitalizing Bankia with $23.5 billion worth of Spanish bonds, that Bankia could then use as collateral at the [European Central Bank] for new money. It that sounds suspiciously like asking the ECB to print money to bail out its banks, that’s because it is.”

So far, it’s unclear whether the European Central Bank is willing to go along with that plan — the Financial Times’ David Keohane tracks some of the early confusion over whether the ECB would agree to essentially inject money into the Spanish banking sector.

Basically, it’s still uncertain just how rickety Spain’s financial sector is. The Spanish government has so far ordered the country’s banks to set aside around $115 billion in capital, all told, to prepare for further losses in the property sector, but housing prices are falling so steeply and the economy’s so terrible that it’s unclear whether that cushion is big enough.

If Spain can’t patch up its banks, can’t it get aid from other European countries? Isn’t that what happened in Ireland?

Right, the alternative is for wealthier European countries — mainly France and Germany — to bail out Spain with lots of money. That’s what they did for Portugal and Ireland. But Spain is much, much bigger and much, much more expensive. To put this in context, Ireland has received about $105 billion in aid, and its housing market has mostly stabilized. By Alcidi and Gros’ estimates, Spain might need more than four times that much. And Spanish Prime Minister Mariano Rajoy, for his part, has said he won’t accept an international rescue.

Are there any other ideas for fixing Spain?

Alcidi and Gros argued that Spain needs a major readjustment: Workers and resources that used to go to construction need to shift elsewhere. But that will take a long time and is hard to do, given that Spain is on the euro. The latest idea from European leaders is to give Spain a little more flexibility on its deficit targets. And Felix Salmon at Reuters also reports on the current suggestions that Europe create a continent-wide “banking union” — so that individual countries wouldn’t have to deal with banking crises on their own. But that idea’s only slowly getting underway.