At 9:20 p.m. on July 3, Mr. McSwain arrested Mr. Aleynikov, 39, at Newark Liberty Airport, accusing him of stealing software code from Goldman Sachs, his old employer. At a bail hearing three days later, a federal prosecutor asked that Mr. Aleynikov be held without bond because the code could be used to “unfairly manipulate” stock prices.

This case is still in its earliest stages, and some lawyers question whether Mr. Aleynikov should be prosecuted criminally, or whether a civil suit may be more appropriate. But the charges, along with civil cases in Chicago and New York involving other Wall Street firms, offer a glimpse into the turbulent world of ultrafast computerized stock trading.

Little understood outside the securities industry, the business has suddenly become one of the most competitive and controversial on Wall Street. At its heart are computer programs that take years to develop and are treated as closely guarded secrets.

Mr. Aleynikov, who is free on $750,000 bond, is suspected of having taken pieces of Goldman software that enables the buying and selling of shares in milliseconds. Banks and hedge funds use such programs to profit from tiny price discrepancies among markets and in some instances leap in front of bigger orders.

Defenders of the programs say they make trading more efficient. Critics say they are little more than a tax on long-term investors and can even worsen market swings.

But no one disputes that high-frequency trading is highly profitable. The Tabb Group, a financial markets research firm, estimates that the programs will make $8 billion this year for Wall Street firms. Bernard S. Donefer, a distinguished lecturer at Baruch College and the former head of markets systems at Fidelity Investments, says profits are even higher.

“It is certainly growing,” said Larry Tabb, founder of the Tabb Group. “There’s more talent around, and the technology is getting cheaper.”

The profits have led to a gold rush, with hedge funds and investment banks dangling million-dollar salaries at software engineers. In one lawsuit, the Citadel Investment Group, a $12 billion hedge fund, revealed that it had paid tens of millions to two top programmers in the last seven years.

“A geek who writes code — those guys are now the valuable guys,” Mr. Donefer said.

The spate of lawsuits reflects the highly competitive nature of ultrafast trading, which is evolving quickly, largely because of broader changes in stock trading, securities industry experts say.

Until the late 1990s, big investors bought and sold large blocks of shares through securities firms like Morgan Stanley. But in the last decade, the profits from making big trades have vanished, so investment banks have become reluctant to take such risks.

Today, big investors divide large orders into smaller trades and parcel them to many exchanges, where traders compete to make a penny or two a share on each order. Ultrafast trading is an outgrowth of that strategy.

As Mr. Aleynikov and other programmers have discovered, investment banks do not take kindly to their leaving, especially if the banks believe that the programmers are taking code — the engine that drives trading — on their way out.

Mr. Aleynikov immigrated to the United States from Russia in 1991. In 1998, he joined IDT, a telecommunications company, where he wrote software to route calls and data more efficiently. In 2007, Goldman hired him as a vice president, paying him $400,000 a year, according to the federal complaint against him.

He lived in the central New Jersey suburbs with his wife and three young daughters. This year, the family moved to a $1.14 million mansion in North Caldwell, best known as Tony Soprano’s hometown.

A video on YouTube portrays Mr. Aleynikov as a disheveled workaholic who suffers through romantic misadventures before finding love when he rubs a lamp and a genie fulfills his wish by granting him a wife. A friend, Vladimir Itkin, says the Aleynikovs are devoted to their children and seem very close.

This spring, Mr. Aleynikov quit Goldman to join Teza Technologies, a new trading firm, tripling his salary to about $1.2 million, according to the complaint. He left Goldman on June 5. In the days before he left, he transferred code to a server in Germany that offers free data hosting.

At Mr. Aleynikov’s bail hearing, Joseph Facciponti, the assistant United States attorney prosecuting the case, said that Goldman discovered the transfer in late June. On July 1, the company told the government about the suspected theft. Two days later, agents arrested Mr. Aleynikov at Newark.

After his arrest, Mr. Aleynikov was taken for interrogation to F.B.I. offices in Manhattan. Mr. Aleynikov waived his rights against self-incrimination, and agreed to allow agents to search his house.

He said that he had inadvertently downloaded a portion of Goldman’s proprietary code while trying to take files of open source software — programs that are not proprietary and can be used freely by anyone. He said he had not used the Goldman code at his new job or distributed it to anyone else, and the criminal complaint offers no evidence that he has.

Why he downloaded the open source software from Goldman, rather than getting it elsewhere, and how he could at the same time have inadvertently downloaded some of the firm’s most confidential software, is not yet clear.

At Mr. Aleynikov’s bail hearing, Mr. Facciponti said that simply by sending the code to the German server, he had badly damaged Goldman.

“The bank itself stands to lose its entire investment in creating this software to begin with, which is millions upon millions of dollars,” Mr. Facciponti said.

Sabrina Shroff, a public defender who represents Mr. Aleynikov, responded that he had transferred less than 32 megabytes of Goldman proprietary code, a small fraction of the overall program, which is at least 1,224 megabytes. Kevin N. Fox, the magistrate judge, ordered Mr. Aleynikov released on bond.

The United States attorney’s office declined to comment and the F.B.I. did not return calls for comment.

Harvey A. Silverglate, a criminal defense lawyer in Boston not involved in the case, said he was troubled that the F.B.I. had arrested Mr. Aleynikov so quickly, without evidence that he had made any effort to use or sell the code. Such disputes are generally resolved civilly rather than criminally, Mr. Silverglate said.

“It is astonishing that the F.B.I. arrested this defendant at all,” he said. Other firms have also sued former employees recently over concern about high-frequency trading software, though two similar cases are the subject of civil suits rather than criminal prosecution.

Six days after Mr. Aleynikov’s arrest, Citadel, the hedge fund, sued Mr. Aleynikov’s new employer, Teza Technologies, which was founded in March by three former Citadel employees. While Teza is not yet conducting any trading, Citadel claimed the former employees had violated a noncompete agreement with Citadel and might even be trying to steal Citadel’s code, causing “irreparable harm.”

As part of the suit, Citadel detailed the extraordinary steps it takes to protect its software. Besides encrypting its programs, the firm discourages employees from writing down details about them. Its offices have cameras and guards, and there are secure rooms that require special codes to enter. The precautions are necessary because Citadel has spent hundreds of millions of dollars developing its software, the firm said.

In its response, Teza said that it had never stolen or tried to steal Citadel’s software, did not ask Mr. Aleynikov to take code from Goldman, and had never seen the code he took. A lawyer for Teza did not return calls for comment.

Meanwhile, in March, the giant Swiss bank UBS sued three former members of its high-speed trading group in New York state court. UBS contended that the defendants had lied to the bank about their plans to work for Jefferies, another firm. Also, one defendant sent some UBS code to a personal e-mail account.

Lance Gotko, a lawyer for the men, said that they had not used the code they took and that it might not be valuable to Jefferies in any case. A lawyer for UBS referred calls to a bank spokeswoman, who declined to comment. A spokesman for Jefferies declined to comment.

A version of this article appears in print on , on page A1 of the New York edition with the headline: Arrest Over Trading Software Illuminates a Secret of Wall St. Order Reprints|Today's Paper|Subscribe