THE DISTANCE this country has traveled in the past few years has seldom been summed up better than in the contrsating performances of two Presidents last week. There was Richard Nixon on television with David Frost, defending illegal government surveillance of Amercican citizens on the grounds that "when the Presidents does it, that means that it is not illegal" - ans setting out this ominous doctrine as matter-of-facts as if he were explaining home truths to a child. And there was Jimmy Carter in the Rose Garden with Attorney General Griffin Bell and leaders of the intelligence community and Congress, unveiling a bill that declares that, even in the most sensitive areas of national-security intellingence-gathering, the President - like all other officials shall be governed by a law.

The two events were not just coincidental. After all, the offenses and revelations of the Nixon years have sparked the whole struggle to redefine how a democratic government should protect both civil liberties and national security. Mr. Nixon inadvertently gave the work another boost last week by reminding the nation how this arrogant notion of presidential power would make constitutional checks and balances irrelevant. A President's actions would be subject to review by Congress and the voters, Mr. Nixon said. But in the next breath he acknowledged that the Huston plan and other covert operations had been meant to be just that - covert and, therefore, not disclosed or debated publicly.

Like Gerald Ford before him, Jimmy Carter ahs rejected all that and more. The Nixon doctrine was an aberration, but administrations since Franklin Roosevelt's had shared the view that, in the narrow field of foreign intelligence-gathering, the executive branch could wiretap and bug citizens without recourse to Congress or a court. The Supreme Court has not ruled on this controversial aspect of constitutional law. Even so, Mr. Carter - like Mr. Ford - has now asked Congress to outlaw warrantless electronic surveillance in the United States as a matter of policy. The new bill even goes beyond last year's by eliminating any reference to residual power that the President may have. This step, although largely symbolic, should help allay some of the apprehensions that stalled the legislative drive in the Senate in the Senate last year.

The hew bill has other refinements, too, reflecting intense bargaining by the Attorney General, intelligence agencies and key legislators, notably Sen. Edward M. Kennedy (D-Mass.) and Gaylord Nelson (D-Wis.). The measure defines potential targets of foreign-intelligence surveillance very narrowly. As Sen. Kennedy emphasized, it would certainly rule out snooping on citizens such as Martin Luther King Jr., Joseph Kraft and Morton Halperin. To get a warrant, executive-branch officials would have to submit detailed justifications to one of seven federal judges picked by the Chief Justice to handle such requests. Warrants, if issued, would be for limited periods and would spell out what could be done.There could be no legal blank checks.

In a field so fraught with complexities, no one can expect to be satisfied with every detail. Sen. Birch Bayh (D-Ind.), for one, is intent on finding a way to regulate the surveillaance of Americans overseas. The nature of congressional oversight remains to be resolved. Other points need attention, too. For instance, the bill would let the Attorney General delegate the peower to approve warrant applications to an Assistant Attorney General. That seems unwise. The pressures from intelligence officials can get very fierce, and a second-level Justice Department officer might not be able to say no when appropriate.

As Congress addresses all of this, the harmony that was displayed in the Rose Garden last week may be a little strained at times. We hope, though, that the basic unity of purpose and cooperative spirit can be sustained. The goal, after all, is vital: to enact a careful, responsible measures so that citizens and officials alike will know that future electronic surveillance in this country will be governed not by presidential conscience or caprice, but by the rule of law.