The federal budget deficit for fiscal 1980, originally estimated by President Carter to be $29 billion when he presented it in January 1979, was instead $59 billion, the Treasury Department announced yesterday.

It was the second-largest deficit in history, surpassed only by the $66.4 billion red-ink figure for 1976, the last year of the Ford administration. The deficit for fiscal 1980, which ended Sept. 30, was $1.9 billion less than the administration's last public estimate made in July.

The sharp but brief recession and an inflation rate far higher than forecast together helped boost outlays to $579 billion, up $47.4 billion from the first estimate.

Meanwhile, the effect of the recession in reducing tax receipts was overwhelmed by the tendency of higher inflation rates to increase them. Revenues for 1980 turned out to be $520 billion compared with the $502.6 billion estimate in the original budget, the department said.

Both liberals and conservatives have criticized the administration for "losing control" of federal spending in 1980, and Carter's Republican opponent, Ronald Reagan, has promised to cut sharply the growth of federal spending if he is elected.

Administration budget officials question whether Reagan or anyone else could have produced a different result in 1980. Except in the defense area, they said they had little choice but to let outlays rise. In defense, Carter had pledged that spending would go up in real terms, that is, after a full allowance for inflation.

The original budget estimates assumed a far better performance by the economy than occurred, to put it mildly. Inflation was forecast to be 7.5 percent in calendar 1979 and 6.4 percent in 1980. It turned out to be 13.2 percent last year and probably will be about 12 percent this year.

Unemployment, on the other hand, was forecast to be 6.2 percent each year. In 1979 it was less than that, only 5.7 percent, but with the recession this year probably will average about 7.2 percent.

These changes in the economy, compared with the forecasts, accounted for $26.9 billion worth of the $47.4 billion increase in spending, according to W. Bowman Cutter, executive associate director of the Office of Management and Budget. Mandatory increases in domestic programs, such as for higher Social Security benefits because of inflation, added up to $20.4 billion of the $26.9 billion.

Another $6.5 billion went to the Defense Department to cover the greater-than-expected inflation, including much higher fuel bills, Cutter said.

What OMB calls "technical reestimates" ate up another $5.9 billion. Most of this money had to be paid out through a variety of large construction accounts -- principally for the Corps of Engineers, the Bureau of Reclamation and the Environmental Protection Agency's sewer treatment grants. Cutter said contractors often speed up work on such projects when a recession hits and they seek to keep their employes on the payroll when their nongovernment business slumps.

The same phenomenon caused a faster rate of spending for defense hardware, which contractors began delivering faster than expected.

"This is the flip side of the spending shortfall we experienced" earlier in the administration, Cutter explained.

Policy changes between January 1979 and the end of the fiscal year raised spending by another $10.1 billion, or 21 percent of the overall $47.4 billion increase. This spending was within the discretion of the administration to omit.

However, of this, $6.8 billion was for high-priority domestic spending, including payments to low-income families to offset soaring energy bills and payments to farmers and grain dealers related to the Russian grain embargo. Also included was the failure of the Government National Mortgage Association to sell home mortgages from its portfolio because high interest rates would have caused GNMA to incur large losses on the sales.

Defense outlays also rose $3.3 billion as a result of policy changes. Most of this money went for higher operating costs associated with sending more naval and other military units to the Indian Ocean.

Congress did its bit, too. It refused to pass Carter's proposed hospital cost containment program, which caused outlays to go up for Medicare and Medicaid by about $1.8 billion. Another $700 million in cost-saving proposals also failed to pass.

Finally, emergencies and disasters -- mostly the influx of Cuban refugees and the eruption of the Mount St. Helens volcano -- cost $1.8 billion more than the $500 million set aside for such contingencies in the original budget.

The fiscal 1980 experience, Cutter said, underscores the very long planning period for a budget and how many things can change. It also shows "how incredibly narrow the discretionary margin in a budget," he added.