“There are all sorts of stories about undercover operations gone bad,” Jeff Silk, a longtime undercover agent and supervisor at the Drug Enforcement Administration, said in an interview. “People are always tripping and falling over each other’s cases.”

Mr. Silk, who retired this year, cited a case that he supervised in which the D.E.A. was wiretapping suspects in a drug ring in Atlanta, only to discover that undercover agents from Immigration and Customs Enforcement were trying to infiltrate the same ring. The F.B.I. and the New York Police Department were involved in the case as well.

To avoid such problems, officials said, they have tightened “deconfliction” policies, which are designed to alert agencies about one another’s undercover operations. But problems have persisted, the officials said.

It is impossible to tell how effective the government’s operations are or evaluate whether the benefits outweigh the costs, since little information about them is publicly disclosed. Most federal agencies declined to discuss the number of undercover agents they employed or the types of investigations they handled. The numbers are considered confidential and are not listed in public budget documents, and even Justice Department officials say they are uncertain how many agents work undercover.

But current and former law enforcement officials said the number of federal agents doing such work appeared to total well into the thousands, with many agencies beefing up their ranks in recent years, or starting new undercover units. An intelligence official at the Department of Homeland Security, who spoke on condition of anonymity to discuss classified matters, said the agency alone spent $100 million annually on its undercover operations. With large numbers of undercover agents at the F.B.I. and elsewhere, the costs could reach hundreds of millions of dollars a year.

In a sampling of such workers, an analysis of publicly available résumés showed that since 2001 more than 1,100 current or former federal employees across 40 agencies listed undercover work inside the United States as part of their duties. More than half of all the work they described is in pursuit of the illicit drug trade. Money laundering, gangs and organized crime investigations make up the second-largest group of operations.

Significant growth in undercover work involves online activity, with agents taking to the Internet, posing as teenage girls to catch predators or intercepting emails and other messages, the documents noted. The F.B.I., Department of Homeland Security and Pentagon all have training programs for online undercover operations.