The spies are not particularly difficult to find. What is difficult is deciding what to do with them.
For more than 70 years, Moscow has filled its embassy and consulates in the United States with intelligence operatives — as Washington does with its own diplomatic outposts in Russia — giving them the mission of stealing the most significant secrets of a longtime adversary. It is the Federal Bureau of Investigation’s job to identify and track the operatives, part of a routine cat-and-mouse game.
But it is a rare and provocative act for the White House or the Kremlin to publicly expel diplomats, as the Obama administration did on Thursday. Current and former government officials described the delicate calculations, and no small amount of gamesmanship, that go into making such decisions.
Sometimes, American presidents decide to expel Russians who are thought to have done real damage with their espionage, and sometimes the expulsions are intended to send a warning shot to Moscow, with the expelled officials serving as pawns in a chess match.
“I think it will have a short-term effect on Russian intelligence collection within the United States,” said Kevin Favreau, a former top F.B.I. counterintelligence officer, speaking of President Obama’s decision to expel 35 Russians and their families.
“But the game will go on,” he said, “and intelligence officers are always replaceable.”
American officials said that in the weeks before Thursday’s announcement, the White House asked the F.B.I. and American intelligence agencies for a list of names of Russians who may have conducted espionage. Mr. Obama had decided to order the expulsions in response to what the administration called a campaign by Russia to disrupt the presidential election, as well as harassment of American diplomats posted in Russia.
The administration decided to target Russians in Washington and San Francisco, a move that former federal law enforcement officials said was not particularly surprising. Jeffrey Harp, a former F.B.I. officer who helped oversee counterintelligence analysis in San Francisco until his retirement in 2015, said the Russians had extensive intelligence-gathering operations in the Bay Area.
“That’s something that’s always been an issue with the proximity to Silicon Valley,” he said. “But it’s not just corporate espionage. The Bay Area is home to a lot of military installations.”
The Russian Consulate in San Francisco, in a Facebook post on Friday, took exception to being called a den of spies. The post described the hardship of “close to a dozen” consular officials who were being forced to fly back to Russia on Saturday, “meeting the new year while in flight.”
It was “bizarre and ridiculous,” the consulate said in the message, to identify the officers as spies. Among those being expelled, it said, was the diplomatic post’s chef, “whose mastery was enjoyed by hundreds of our guests” for three years. “We will not be able to treat you with authentic Russian food any more,” the message said.
Former officers said the F.B.I. considered a number of factors when deciding whom to expel.
Generally, Mr. Favreau said, “it would be those diplomats who are most suspected of being involved in active political, military or economic intelligence activity collection.” In other words, the Russians thought to be having the most success in stealing American secrets.
But sometimes there are more strategic considerations at play. During the Cold War, the F.B.I. sometimes kept active Russian spies off its expulsion lists so that Moscow might suspect that they had been recruited as American agents.
“The bureau would play a little game,” said Ray Batvinis, who spent 25 years as an F.B.I. counterintelligence officer until his retirement in 1997. “They wanted to foster a bit of suspicion.”
Mr. Batvinis said that during the Reagan administration, the F.B.I. often clashed with the Central Intelligence Agency and the State Department over the wisdom of expelling Russian spies. The other two agencies worried that such a move would prompt the Kremlin to thin the ranks of American diplomats and spies in Russia.
At the height of the Cold War, the Russian intelligence presence in the United States was so much greater than that of the C.I.A. in Russia — possibly by a 10-to-1 ratio, Mr. Batvinis said — that any move by Moscow to expel C.I.A. officers could significantly weaken the agency’s operations in Russia.
That dynamic changed in late 1986, when President Ronald Reagan became so angry about a string of damaging thefts of American secrets that he expelled 80 Soviet diplomats. The Soviets responded by expelling dozens of American government employees.
Little has changed since the Cold War for F.B.I. counterintelligence officers who track Russian spies. Their job is to follow and sometimes harass operatives working for Russian intelligence agencies, as well as to try to recruit them as American agents.
The recruitment efforts have had some success, according to former law enforcement officials, and in recent years the F.B.I. even believed that it might be able to lure the Washington chief of Russia’s foreign intelligence agency, known as the S.V.R. In the end, the man refused the bureau’s overtures.
Last year, the F.B.I. broke up an S.V.R. spy ring in New York when officers arrested a Russian man working for a bank under nonofficial cover. That led to the expulsion of two S.V.R. operatives. According to a criminal complaint, the F.B.I. had been closely monitoring a Manhattan office used to transmit intelligence to headquarters in Russia.
The F.B.I.’s head of counterintelligence called the case “egregious,” and former bureau officials said that over the past year, some in the F.B.I. wanted to make several more arrests similar to the one in New York.
Those requests were denied, they said, out of concern for what the Russians might do to retaliate.