WASHINGTON (AP) -- The United States has now spent $1 trillion more than it's taken in for four straight years.

The Treasury Department confirmed Friday what was widely expected: The deficit for the just-ended 2012 budget year — the gap between the government's tax revenue and its spending — totaled $1.1 trillion. Put simply, that's how much the government had to borrow.

It wasn't quite as ugly as last year.

Tax revenue rose 6.4 percent from 2011 to $2.45 trillion. And spending fell 1.7 percent to $3.5 trillion. As a result, the deficit shrank 16 percent, or $207 billion.

A stronger economy meant more people had jobs and income that generated tax revenue. Corporations also contributed more to federal revenue than in 2011.

The government spent less on Medicaid and on defense as U.S. military involvement in Iraq was winding down.

Barack Obama's presidency has coincided with four straight $1 trillion-plus annual budget deficits — the first in history and an issue in an election campaign that ends in 3½ weeks.

When Obama took office in January 2009, the Congressional Budget Office forecast that the deficit that year would total $1.2 trillion. It ended up at a record $1.41 trillion.

The increase was due in large part to the worst recession since the Great Depression. Tax revenue plummeted, and the government spent more on stimulus programs.

Tax cuts enacted under President George W. Bush and military spending in Iraq and Afghanistan contributed to the deficits.

"There is nothing like the number trillion to focus the mind," says Maya MacGuineas, president of the Committee for a Responsible Federal Budget, which advocates budget discipline. "The fiscal situation is terrible. Changes will have to be made as quickly and carefully as possible."

Here's a closer look at the nation's deficit and its debt, which represents the accumulation of annual deficits:

— ROOTS OF THE PROBLEM

The 2012 budget gap signals a slight recovery from the deficit explosion that hit in late 2008. That's when the financial crisis erupted and the recession that began in December 2007 was tightening its grip.

Story continues

The sinking U.S. economy caused tax revenue to plummet. And federal spending surged. The money went to provide laid-off workers with unemployment insurance and food stamps. The government also spent more to provide economic stimulus programs and to stabilize the financial system.

Before it escalated, the deficit had been as low as $161 billion in 2007. By 2009, it had peaked at $1.4 trillion. Since then, the improvement has been slight but steady. Tax revenue is still less than in 2007.

— THE OUTLOOK

The aging of the vast baby boom generation is raising government spending on Social Security and on Medicare and Medicaid.

A still-weak economy, along with tax cuts, have meanwhile reduced government revenue. Over the past three years, revenue has fallen below 16 percent of gross domestic product — the value of all goods and services produced in the United States. It's the lowest such percentage since 1950. That isn't enough to sustain spending, which has been exceeding 22 percent of GDP.

And so the government has borrowed to make up the gap. And debt piles up, year after year. It's reached $11.3 trillion — $16.2 trillion if you include money the government has borrowed from itself, mostly revenue from Social Security.

Unless something changes, the Congressional Budget Office warns, the federal debt would reach a level that is "unsustainable from both a budgetary and an economic perspective."

Still, Treasury is benefiting from record-low interest rates. Those rates make it cheaper to borrow. Interest payments on the debt fell 2 percent this year to $223 billion.

For the current 2013 budget, the administration predicts a deficit of $991 billion. Its slightly brighter outlook reflects lower spending on defense, health care, unemployment benefits and Medicaid payments to states — all of which declined this year.

Many private forecasters are less optimistic about the deficit. Analysts at JPMorgan foresee a $1 trillion budget gap for 2013. That would mark a fifth straight year of deficits of at least $1 trillion.

All that assumes the country avoids tax increases and deep spending cuts that take effect next year unless Congress reaches a budget deal.

— THE THREAT

Over time, big government debts can damage the economy. The economists Kenneth Rogoff of Harvard University and Carmen Reinhart of the Peterson Institute for International Economics have found that growth tends to slow sharply once national government debt reaches 90 percent of GDP.

When the government borrows heavily, it can drive up interest rates and divert financing that would have been available for private companies.

Rising debt levels can cause some investors to lose confidence in the government's ability to pay its bills. They would demand substantially higher interest rates.

Higher rates would discourage businesses and consumers from borrowing, thereby slowing the economy. The government would collect less in taxes and spend more on unemployment benefits and other social programs.

That creates a vicious cycle like the one that has entrapped European countries such as Spain, Italy and Greece; Rates are rising, economies buckling, budget deficits widening and debts swelling. So far, that hasn't happened to the United States.

Investors, worried about the troubles in Europe, have been eager to buy Treasury debt, allowing the federal government to borrow at historically low rates.

— THE FIX:

If he's elected to a second term, Obama has pledged to reduce the government's deficits over the next 10 years by about $4 trillion. Obama says he would reduce the growth of federal spending — slowly, to avoid triggering another recession. He also wants to end the Bush-era tax cuts on income that exceeds $200,000 people for single taxpayers and $250,000 for couples.

Republican challenger Mitt Romney says he would also reduce spending growth by capping it at 20 percent of the economy by 2016. In 2012, spending has accounted for about 23 percent of the economy.

Romney would preserve the Bush-era income tax cuts for all taxpayers, regardless of how much they earn. The economy is too weak to raise taxes on anyone, Romney has argued.

He says his plan to cut income tax rates for everyone by an additional 20 percent would help produce more tax revenue. And he says he would reduce the deficit in part by curbing some tax loopholes and deductions.

Complicating the political options is a crisis that Congress must first resolve: A budget deadlock could send the economy over a "fiscal cliff" next year, when tax increases and deep spending cuts will take effect unless a budget deal is reached.

After the elections, Congress may address the budget crisis during a lame-duck session.