“No matter where you are, we are a target these days,” said R. James Woolsey Jr., the director of central intelligence during the Clinton administration. “No matter where we go, countries like China, Russia and much of the Arab world have assets and are trying to spy on us so you have to think about that and take as many precautions as possible.”

On a trip to Latin America in 2011, for example, a White House photo showed Mr. Obama talking from a security tent in a Rio de Janeiro hotel suite with Hillary Rodham Clinton, then the secretary of state, and Robert M. Gates, the defense secretary at the time, about the air war against Libya that had been launched the previous day. Another photo, taken three days later in San Salvador, showed him conferring from the tent with advisers about the attack.

Spokesmen for the State Department, the C.I.A. and the National Security Council declined to provide details on the measures the government takes to protect officials overseas. But more than a dozen current and former government officials, most of whom spoke on the condition of anonymity, described in interviews some of those measures.

They range from instructing officials traveling overseas to assume every utterance and move is under surveillance and requiring them to scrub their cellphones for listening devices after they have visited government offices, to equipping the president’s limousine, which always travels with him, to keep private conversations private. Mr. Obama carries a specially encrypted BlackBerry; one member of his cabinet was told he could not take his iPad on an overseas trip because it was not considered a secure device.

Countermeasures are taken on American soil as well. When cabinet secretaries and top national security officials take up their new jobs, the government retrofits their homes with special secure rooms for top-secret conversations and computer use.