"Politics and protection," an aide to the late President Kennedy once said, "don't mix."

A Secret Service official voiced that theme again yesterday after the attack outside the Washington Hilton Hotel that left President Reagan and three others wounded, one critically. Guarding a president, the agent made clear, always starts as a compromise. It always involves a calculated risk.

Hard questions will still be asked in the wake of yesterday's shootings. With all the tightening of security that has presumably taken place since John F. Kennedy was murdered in Dallas nearly 18 years ago, how is that a gunman can still get that close to the president of the United States?

Part of the answer lies in a strategic decision by the Secret Service, a compromise. It can seal off the White House, it can seal off a banquet room, but it has decided it simply cannot seal off a public sidewalk because the president happens to be walking on it.

"We are a defensive force, period," one agent explains. "The detail around the president is thinking 'defense' and 'escape route' all the time. They're saying to themselves, 'How do I guard this guy?' and 'How do I get him out of here?'"

By those standards, at least one Secret Service veteran who watched videotapes of the attack observed yesterday that the agent closest to the president, the man "working the body," as the assignment is called did what he was trained to do.

Rather than looking for the attacker, the agent, Jerry Parr, chief of the Secret Service's White House detail, found the quickest escape route, he grabbed Reagan and threw him bodily into the bulletproof presidential limousine, which raced away immediately.

It was not immediately, clear whether the suspect, John W. Hinckley, Jr., had ever been identified by the Secret Service on its extensive lists as a threat to the president, or whether he should have been. Secret Service agents familiar with those considered potential assassins in any given city always accompany the presidential party, but Hinckley appears to have been just another face in the crowd.

According to ABC camerman Henry M. Brown, the gunman had "penetrated the press line" and stationed himself among the members of the press who are traditionally allowed to get closer to the president following a public appearance for a few parting words and pictures.

Brown said that he and other camera crew members had complained to the Secret Service that four to five dozen other bystanders had pushed into the press "pen" by the Hilton's side entrance. He said the agents moved some away, but others strode up as Reagan was leaving.

Secret Service agents regularly protest that the number of aides and reporters cleared to cover political candidates is so large that it is often difficult to spot an interloper.

The problems have been studied time and again since President Kennedy's assassination. Procedures have improved, but the fact remains that it is not easy, and perhaps not fitting, for the Secret Service to order a president around. As late FBI director J. Edgar Hoover said in a memo to the White House shortly after Kennedy's murder, the amount of security afforded a president depends considerably on the amount of contact he wants with the general public.

"Absolute security is neither practical nor possible," Hoover wrote. "An approach to complete security would require the president to operate in some sort of vacuum, isolated from the general public and behind impregnable barriers. His travel would be in secret; his public appearances would be behind bullet-proof glass."

The National Commission on Violence, however, clearly thought presidents and presidential candidates should show more restraint. Appointed after the 1968 killings of Sen. Robert F. Kennedy and the Rev. Martin Luther King Jr., the commission recommended sharp curtailment in public appearance and heavier reliance on television.

"We urged less mingling with crowds," Washington lawyer Lloyd M. Cutler, who served as the commission's executive director, recalled yesterday. "We frowned, for example, on walking around the perimeter of an airport and shaking hands. But you can't get any president not to do that. Carter was one of the worst."

Reflecting on yesterday's attack, Cutler suggested that a less conspicuous exit might have been used, but he added, "Usually that's what the Secret Service wants, but then somebody sets that aside -- because he press is out there, the photgraphers are waiting. . . ."

In the end, Cutler maintains, "you come right back to guns. Virtually every assassination attempt has been with handguns. Our principal recommendation was for the control of handguns. It is the best practical solution, but of course, you know what the [political] problems are with that."

Hinckley, it was learned last night, had been arrested at the Nashville airport Oct. 9 on charges of carrying three concealed handguns, but he forfeited bail and was never brought to trial. President Carter was in Nashville Oct. 9.

The Secret Service maintains a list of some 20,000 individuals who are "at one time or another have exhibited an interest in people we protect that might be regarded as a threat," Secret Service Director H. Stuart Knight told United Press International last week. Knight said there is also a smaller list of about 400 people the service considers a serious threat to the president.