By David Henry and Lauren Tara LaCapra

NEW YORK (Reuters) - As the United States threatened to default on its debt last month, major U.S. banks set up war rooms, spent many millions of dollars on contingency planning and, in some cases, even prepared to underwrite federal government benefits.

In a series of interviews with top bank executives, new details emerged about the extent of the contingency planning that was undertaken before and during the 16-day government shutdown and as a potential default loomed.

The planning for worst-case scenarios didn't come cheap. JPMorgan alone has spent more than $100 million on contingency planning for U.S. budget crises in recent years including this one, sources close to the bank say. It has reviewed and analyzed thousands of trading contracts, updated computer systems to handle fiscal emergencies, hired consultants, and built new models to figure out what might happen to securities prices.

It may not go to waste. The temporary budget agreement that President Barack Obama signed shortly after midnight on October 17 to end the shutdown and lift the default threat, authorizes government spending through January 15 and eases enforcement of the debt limit until February 7, creating the potential for another budget crisis early next year, even as some Republicans vow they will avoid it.

With each crisis, the once-unthinkable scenario of a U.S. default becomes a little more real, bank executives said.

"You could tell in the market that people were getting prepared much more this time for a potential default than last time," said a person involved with contingency planning at a major U.S. bank. "The threat moved the market, and people were preparing, whereas the first time there was little movement because most people didn't think it would happen."

The latest budget dust-up was the third in two years. In August 2011, fiscal battles led to the downgrade of the U.S. credit rating by Standard & Poor's, and then 16 months later, the discord resulted in across-the-board budget cuts at federal agencies known as "sequestration."

THE "RIGHT THING TO DO"

In October, officials at JPMorgan Chase & Co (JPM.N) asked Chief Executive Jamie Dimon how to handle the government benefits that many of its customers receive monthly.

Some of the bank's retail customers depend on government programs like Social Security and food stamps to pay their bills, and Dimon decided the bank would pay the benefits out of its own pocket if it had to.

"We're going to fund them," he said, according to a person at the meeting. "It is the right thing to do."

Staff in the legal, finance and risk departments, were reluctant, and although they had to listen to Dimon, they found potential hurdles. The bank would have had to have paid an estimated $5 billion of cash every month, and it was not clear how the money could be legally recouped.

JPMorgan's legal staff determined that, by law, customers' Social Security checks cannot be used as collateral for short-term loans. It was also unclear how regulators would assess the riskiness of the loans it was making.

Other banks gave their customers concessions because of the crisis in Washington. Wells Fargo (WFC.N), for example, waived late fees for those who were tardy with their mortgage payments in October.

The biggest question was how markets would have reacted to a default, bank executives said. It was entirely possible that panic could have spread across multiple assets, creating conditions as treacherous as in September 2008 when the collapse of Lehman Brothers touched off the worst of the financial crisis and the deepest recession since the Great Depression, Wall Street executives said.

However meticulous the planning, a panic is almost impossible to guard against, top bankers said.

And even if there is no default, the threat of one is bad news for Treasury debt. U.S. government bills, notes, and bonds are seen as assets without credit risk that form the basis for pricing securities globally, and every time a default looms, that status is threatened, said an executive at Goldman Sachs Group Inc (GS.N).

MANY UNKNOWNS

Executives said that preparing for a default was difficult, because there were so many unknowns. No one was sure what the value of defaulted bonds would be if the government really had failed to make payments. Those questions could have hurt trading in multiple markets, which in turn raised questions about how the Federal Reserve might intervene.

Story continues