Budget director David A. Stockman is approaching a political day of reckoning, a "once-in-a-generation" opportunity he has sought for a decade, to roll back popular middle-class spending programs in the battle against federal deficits.

The time has come, he told Republican congressional leaders privately last week, "to think the unthinkable."

Close Stockman associates say that is the explanation for his extraordinary behavior last week when, on successive days of congressional testimony, he blasted three of the most entrenched groups in U.S. society: the armed forces as caring more about their retirement program than national security; farmers as seeking federal bailouts to take the risk out of business decisions; college presidents as caring more about their finances than about their students.

His friends say these outbursts were no accidents. They portray the director of the Office of Management and Budget as believing that this year is the "last chance" to press through Congress permanent changes that would shrink government's involvement in American life.

"Dave has decided he will let his hair down and speak his piece," said Lawrence A. Kudlow, Stockman's chief economist at OMB in President Reagan's first term. "His level of worry and anxiety has been increasing."

Reagan, who nearly fired Stockman for speaking out on the budget in 1981, again was described as "upset" last week with what one official called the "impolitic" remarks of his outspoken subordinate. Reagan told The Wall Street Journal on Friday that he disagreed with Stockman on military pensions.

But Stockman's associates said that he is not sorry for his remarks, and that they foreshadow what may be a final, determined effort to cajole Congress into making cuts in many of the political "sacred cows" in the federal budget.

"I don't envy David Stockman's position, but he has to take the varnish off," said Senate Majority Leader Robert J. Dole (R-Kan.)

For four years, since he confessed to doubts about the Reagan program in a 1981 article in the Atlantic Monthly, there has been almost constant speculation about when Stockman would quit in frustration. But officials said last week that Stockman now is "spoiling for this one."

Stockman repeatedly has issued warnings about the dangers of the deficit, leaving many officials skeptical of his "last chance" exhortations. But many GOP strategists share Stockman's assumption that this year offers the best opportunity of Reagan's second term to win politically painful spending cuts from Congress.

If the budget-cutting drive falls apart now, they said, Stockman, 38, likely will leave, perhaps as soon as April, when his wife, Jennifer, is expecting their first child.

But Stockman is staying for at least a while longer because he sees Reagan's six- to nine-month "window of opportunity" as a chance to test the political system, officials said.

"His pessimism of last spring and summer, about the capacity of the political system to do the kinds of stuff we've proposed, has changed to a kind of excited combativeness," a Stockman aide said. "He wants to see -- on the odd chance that just maybe it can be done."

What Stockman wants to do is pare the large federal spending programs that benefit the middle class and business. This was the theme of Reagan's fiscal 1986 budget proposal, and promises to be a major element of the second phase of Reagan's presidency. In the first phase, Reagan and Stockman squeezed low-income programs while rebuilding the military and cutting taxes.

Stockman has longed to tackle the middle-income programs for a decade or more, but in Reagan's first term he was largely thwarted by Congress. He has thrown himself back into the effort, having won Reagan's imprint on a budget chock full of his own longstanding policy choices.

For example, he angered veterans and Defense Secretary Caspar W. Weinberger last week with his scathing remarks about the $18.3 billion military retirement system, saying Pentagon officials are "more concerned about protecting their retirement benefits than they are about protecting the security of the American people."

But Stockman made a similar point 10 years ago this spring in "The Social Pork Barrel," an article published in The Public Interest, a neoconservative journal. He called military pensions "overly generous," and attacked veterans benefits for ex-servicemen "who do not even have a hangnail to show for their harrowing experiences in uniform."

In this year's budget, Stockman tries to stop what he calls "an unrestrained, 20-year binge" of spending on college student aid. A decade ago, when student aid was less than a fifth of what it is now, Stockman wrote that "too large a share" of the budget "is already being devoted to higher education relative to other priorities."

This year's budget document is sprinkled with other Stockman criticisms of federal programs that largely benefit middle-class Americans or subsidize business:

* Farm subsidies are "paying for a bizarre combination of federal benefits," in which "taxpayers pay for excess production," then "pay to cut production," and finally "pay to subsidize exports to get rid of the surplus because the first two actions artificially raise farm prices above world market levels."

* The postal subsidies approved by Congress have led to "taxpayer support for profit-makers like People and Playboy magazines."

* The cost to taxpayers for each Job Corps slot is $15,200, which "nearly equals the annual cost of sending a student to Harvard or Stanford . . . ."

* Amtrak is a "middle- to upper-income subsidy."

* Urban Development Action Grants are "an expensive taxpayer-supported shell game which lures jobs and investment from one location to another . . . ."

* Most small businesses "get along fine without . . . assistance or credit subsidies" from the Small Business Administration.

"Who would have ever thought a year ago we would have ever proposed abolishing the SBA?" Stockman asked rhetorically last week at a meeting with Reagan and GOP congressional leaders. The time has come, he said, "to think the unthinkable," according to a participant.

Stockman had "given up" on eliminating such programs in the election year, but now believes a "propitious combination of circumstances" may change that, a senior budget official said.

One circumstance is Reagan's reelection victory and continued strong political standing. A second is the pressure created for budget-cutting by the high projected deficits. A third is that the economy continues to expand, making it easier for Congress to ask for sacrifice from voters than it would be in time of recession.

Another factor is the future of the Republican-controlled Senate, where 22 of 53 GOP members are facing reelection next year. Stockman wants to capitalize on their early anxiety about holding onto the Senate by urging them to push through a difficult package of budget cuts this year.

Dole has taken the lead. But if he fails and the package stalls, the next elections could quickly become a boomerang, creating pressures on individual members not to cut such popular programs as farm price supports and small business subsidies when the campaigns draw nearer.

Stockman, a former Michigan congressman, "recognizes that this budget problem is increasingly becoming a Republican Party problem and a Ronald Reagan problem," Kudlow said.

"The ability for the Republicans to blame it on liberal Democrats is fast receding," Kudlow said. "Tip O'Neill is going to retire. What he sees more than most is that the failure to execute budget restraint will be placed in the lap of the GOP in 1986, in 1988. Any economic or interest rate problems are going to be blamed on the deficit, on the president and on the Republican Party."

"He sees that party realignment can be thwarted," Kudlow said. This apparently is one reason Stockman tried to steer away from deeper cuts in low-income programs this year, to guard against a revival of the "fairness issue," officials said.

But critics, such as Robert Greenstein, a former Carter administration official who now is director of the Center on Budget and Policy Priorities, an advocacy group for the poor, said Stockman tried to "camouflage the cuts" in social programs, a charge Stockman denied.

Even so, Greenstein said, "I admire what he did" in speaking out against military pensions. "While he almost can't stop himself from almost endlessly massaging the numbers, there are these other issues, like on military retirement, and discussions of 'trickle down' in the Atlantic Monthly interview where a streak of occasional brutal frankness comes to the surface," he said.

Stockman's remarks on military pensions may have stemmed from another long-simmering frustration: Reagan always has made the defense buildup a higher priority than reducing the deficit.

Since 1981, Stockman has tried repeatedly and unsuccessfully to slow the military buildup. But the president generally rejected his advice, Congress bought a five-year, $1.2 trillion Pentagon budget, and now the bills are coming due in a huge "bow wave" of spending.

"Those who loudly advocate a defense budget authority freeze are playing Rip Van Winkle," Stockman said last week in Senate testimony.

"After five years of voting for nearly all the program elements which drive the 1986 budget cost, they now shout, 'The number is too big.' But they have not explained which previously accepted weapons systems they would forgo . . . ."

Stockman also has raised the ire of supply-side tax cutters who say he is preoccupied with the deficit and pursuing a hidden agenda: tax increases.

This week, Stockman suggested that, given the increasing share of the economy claimed by government spending in the Reagan years, the original 1981 tax cut "clearly went too far" -- a heresy among the supply-siders.

But, Stockman said, five tax increases since then have "fully restored" revenues to the point "where the American people have drawn the line" against any more tax increases.

One of the uncertainties in Stockman's future is the loss of James A. Baker III as a White House ally when Baker became treasury secretary. Stockman's credibility with the president never quite recovered from his fall in the first year, but Baker repeatedly stood behind him later on.

After his sharp criticism of farmers and military pensions last week, White House chief of staff Donald T. Regan said Stockman "lost his cool under pressure."

Privately Regan chided the budget director, giving him a clear indication that he does not have a mainstay of support as he once did in the White House.