The Gramm-Rudman-Hollings budget law is reshaping politics on Capitol Hill, with centrists in both parties taking control to put President Reagan on the defensive as never before.

In both the Democrat-controlled House and Republican-run Senate, centrists have produced fiscal 1987 budgets that would sharply curtail the president's military buildup, move tax increases back onto the bargaining table and shield most social welfare programs from further retrenchment. And despite much rhetoric to the contrary, the House and Senate have moved closer to each other and farther from the White House.

The centrists have shifted the battle from guns versus butter, where the Reagan administration had the upper hand in earlier years, to guns versus taxes. Ultimately the administration and congressional conservatives could be forced to choose among their own top priorities, and House Democrats have skillfully positioned themselves to force Reagan into that choice while protecting themselves.

The main issue in the House-Senate conference on the fiscal 1987 budget is expected to be the disparity in defense spending. The House bill allocates $285 billion in spending authority for defense and the Senate $301 billion. Although many lawmakers expect a compromise fairly near the Senate number, the House is not without bargaining power.

House Democratic leaders have signaled willingness to compromise on defense but say they won't go along with new taxes unless Reagan "embraces" them. The House can drop taxes from its budget because, with its low defense figure, it meets the Gramm-Rudman-Hollings deficit-reduction target of $144 billion for fiscal 1987 without them. But the Senate has no such cushion and needs additional revenue to sustain its higher defense figure. So, if the House bails out on taxes, the Senate is presumably faced with cutting its defense number to meet the deficit target unless it is willing to tamper with the delicately balanced consensus on domestic spending.

This puts pressure right where the House Democrats want it: on the Senate Republicans to force the White House to choose between taxes and defense.

Another reflection of how the political wind has shifted on Capitol Hill is the strange reviews being given the Gramm-Rudman-Hollings law.

As Reagan was firing off a blistering letter denouncing the way House Democrats used the new law to cut defense, Speaker Thomas P. (Tip) O'Neill Jr. (D-Mass.) was giving the legislation a grudging tribute as a major factor in stimulating financial markets, reducing inflation and interest rates, demonstrating "stability" in Congress and restraining budget growth.

By setting rigid annual deficit targets and holding out the threat of automatic, across-the-board spending cuts if the targets are not met, Gramm-Rudman-Hollings makes just about anything else look easy and attractive.

"It's tightened the playing field, 50 yards instead of 100, . . . and it's taken the heat off of some of the tough decisions," said Rep. Leon E. Panetta (D-Calif.), a respected veteran of the budget wars.

"The threat of sequester automatic cutbacks has forced people to compromise and make choices sooner rather than later, which was the purpose of the whole thing to begin with," said Sen. Warren B. Rudman (R-N.H.), who cosponsored the legislation with Sens. Phil Gramm (R-Tex.) and Ernest F. Hollings (D-S.C.).

As the law's first year unfolds, Reagan has powerful cards to play, including threats to veto tax increases and domestic spending that exceed his wishes. Dire Reagan warnings about the effect of defense cutbacks, contained in the letter last week to House Republicans, didn't appear to have much effect on the budget vote. But during a time of international crisis a similar campaign could have more impact, especially among Democrats easily unnerved by charges that they have been soft on defense.

But the president has suffered a serious setback in the early rounds, and House Democrats have stacked the deck to make it harder for him to hold out simultaneously against tax increases and for more defense spending and then blame the Democrats when stalemate occurs.

Even without Gramm-Rudman-Hollings, military spending was losing its charm among many of its backers in Congress as voters, angered at reports of overpriced aircraft toilet covers and tax avoidance by defense contractors, vented the same wrath on the Defense Department that they once reserved for welfare programs that had become identified with waste, fraud and abuse. Many lawmakers have also grown impatient with Defense Secretary Caspar W. Weinberger's reluctance to compromise on spending.

But the new law gave them the legislative mechanism -- and the political camouflage -- for reining in the Pentagon budget by requiring automatic cutbacks of equal proportions from defense and domestic spending if annual deficit targets are not reached by voluntary congressional action.

With strong political pressures against more severe cuts in domestic spending, it became almost impossible to ignore defense, the biggest and fastest-rising category of discretionary spending, as a source of savings. And lawmakers could either blame Gramm-Rudman-Hollings ("the Devil made me do it") or claim that they were "doing the Lord's work" of deficit reduction.

If all else failed, they could claim that their defense totals, although considerably short of Reagan's $320 billion, were far above the anticipated $270 billion ceiling of the automatic cutbacks.

The Gramm-Rudman-Hollings leverage also made it easier to persuade liberals to go along with more domestic retrenchment than they might otherwise have accepted. "Liberals suddenly saw that defense, for the first time, was paying a price, and so they were willing to play ball" on domestic spending, Panetta said.

The trade-offs meant that the House Democratic budget passed on a roughly party-line vote of 245 to 179, with relatively few Democratic defections on either left or right. Similar trade-offs in drafting a bipartisan Senate budget produced an even more lopsided vote of 70 to 25. Even a rejected House Republican budget reflected the consensus on domestic spending, while substantially reducing Reagan's defense request to $293 billion.