The U.S. Treasury posted a surplus in December, thanks partly to payments from Fannie Mae and Freddie Mac.

The Bureau of the Fiscal Service reported Monday that the U.S. government took in $53.2 billion in December, following a $1.2 billion deficit in December 2012.

Over the first three months of fiscal 2014, the government has run a $174.6 billion deficit, a 40 percent decrease from the year before.

December's relatively rosy numbers are mostly due to a one-time payment of roughly $40 billion from the bailed-out government-sponsored enterprises Fannie Mae and Freddie Mac. The government took control of the two failed mortgage businesses in 2008, an intervention that ultimately cost taxpayers $187.5 billion. Since then, the two GSEs have turned $185.2 billion, which represents a return on investment for the government rather than payback for the bailout.

Receipts, led by payroll taxes, are also up from last year. Spending, meanwhile, is down from $908.9 billion last year to $838.2 billion in 2014.

The federal deficit clocked in at $680 billion in 2013, down from $1.1 trillion in 2012 and the first sub-$1 trillion budget since 2008.

Treasury Secretary Jack Lew has said that he will run out of room under the debt ceiling sometime in mid-February to early March if it is not raised. Monday's larger-than-expected surplus likely means that the date by which the debt ceiling will become binding falls toward the later end of that range.