“We used to be able to talk to investigators on drug trials,” says Source A, a hedge fund portfolio manager. Like all the analysts, research directors, and portfolio managers who cooperated for this article, Source A requested anonymity. People don’t want their names in a story about gray areas of equities research that border on insider trading.

Four or five years ago, Source A continues, he and other health care analysts still used to get in touch with doctors who were serving as investigators on Phase II or Phase III trials, studies required by the U.S. Food and Drug Administration before a pharmaceutical can be approved as safe and effective. He might have been able to reach as many as eight out of 10 investigators running a study, and sometimes he could reach the principal investigator, the overseer of the whole thing.

“Say each investigator has 11 patients,” Source A continues. “You could almost go patient by patient,” asking how they were doing.

The outcome of these drug trials would have an enormous impact on the stock price of the pharmaceutical firm developing the drug. For a small company, the stock might go down 90% or up 100%, depending on the result, and even the stock of a big company, like Pfizer, might move 5%.

The doctors on these studies were providing the analysts with nonpublic information. They may well have been violating confidentiality agreements they had signed with the pharmaceutical companies that commissioned the studies. Source A was paying the doctors for their information, in that he’d reach them through expert-network firms that his hedge fund had on retainer, and the networks paid the doctors for their time.

Isn’t that insider trading? In fact, doesn’t it sound a lot like the top charge currently being leveled in the marquee insider-trading case of our time: the indictment, filed in July, against Steven A. Cohen’s hedge fund, SAC Capital Advisors, which the government alleges made $276 million in July 2008 by obtaining nonpublic information from a doctor overseeing a study of an Alzheimer’s drug?

Yet Source A doesn’t think his conversations with drug-study doctors in the past ever crossed the line from good, aggressive research into criminality. As we’ll see, he’s probably right.

This story is about the layers of gray that wash over the world in which hedge fund portfolio managers and stock analysts operate, a world of which the general public knows little. It’s about what insider trading is, why it’s so hard to define, why prosecutors and regulators like it that way, and why analysts don’t.

To be sure, neither Source A nor most of his peers contact drug-study doctors anymore. But that’s not necessarily because it was illegal then or now. Rather, it’s because general counsels and compliance officers across the industry have gotten a lot antsier about keeping their colleagues from getting anywhere close to the line. The primary stimulus for the new scrupulousness is no mystery. In the summer of 2006 Manhattan U.S. Attorney Preet Bharara commenced a massive insider-trading investigation that burst into public view in October 2009 with the arrest of Raj Rajaratnam, founder and head of the $7 billion Galleon Group hedge fund. So far, Bharara has arrested 83 individuals, of whom 74 have already been convicted.

His top target is Cohen, who has not been criminally charged but who does face a civil suit by the U.S. Securities and Exchange Commission that seeks to ban him from the industry for life. (Cohen has denied wrongdoing.) Cohen’s family of funds may be the most prosperous ever, employing about 1,000 people and managing, at its peak, $15 billion in assets. The fund has rewarded investors with annual returns as high as 70% in some years, even when netted of Cohen’s staggering fees: 3% of assets, plus 50% of profits.

Should we pity, then, the 83 people caught up in Bharara’s net so far? Are they being persecuted for having stepped over lines that are too murky to make out, or for conduct that has become illegal only in retrospect?

Emphatically no. Every source contacted for this article — including Source A — says that when it comes to criminal prosecutions, the U.S. attorneys exercise their discretion well, and the conduct the indictments allege crosses the line in anyone’s book.

At the same time, when you understand how murky the law is, you do see why it would be so difficult for the government to prove wrongdoing by Cohen himself, notwithstanding the six guilty pleas by his former portfolio managers and analysts. Emails that might look like red flags to you or me — or, indeed, to U.S. Attorney Bharara — may look innocuous and even routine to practitioners of the gray art.

“The fact is, there are many gray areas,” says Catherine Botticelli, who represents investment professionals in enforcement proceedings and compliance matters for the Dechert law firm. “And there are hundreds of reviews and investigations that you never hear about,” she adds, referring to inquiries by the SEC or by the Financial Industry Regulatory Authority (FINRA).

These can be expensive to deal with and, for the funds involved, terrifying, because hedge funds are what lawyers call “eggshell defendants,” for which adverse publicity can be fatal.

One subpoena can sink a firm, says Source B, the executive of another hedge fund. “Our investors are fiduciaries themselves,” he explains, referring to the fact that 60% of the industry’s assets come from university endowments, pension funds, charitable foundations, and the like. “They’re not going to wait around to find out if you’re indicted,” he says. (During Bharara’s investigation, at least six funds where employees were arrested have folded, including three at which no principals have been charged. Investors have reportedly sought to withdraw $5 billion from SAC Capital this year, and its survival to date rests largely on the fact that about $8 billion of its assets are Cohen’s own.)

So if we need not shed a tear for those who have been arrested, we might nonetheless indulge a speck of sympathy for those whose daily challenge is to play by the rules on this mine-ridden field, aggressively competing against rivals who might not be so conscientious. In the end, they are something like investigative journalists without the shelter of the First Amendment. Their work, when done well, provides the market with accurate information about stock values, so that the public need not rely solely on the pablum of corporate press releases.

“There is an important value that good fundamental analysis provides,” says Source B. “We want people kicking tires and uncovering frauds, so public pension funds aren’t invested in Enron. Every investor in the country has an interest in all of this.”

Let’s go back to Source A. Why wasn’t he guilty of insider trading if he was paying doctors for nonpublic information about drug trials they were involved in? And if he wasn’t guilty, why does the government think SAC Capital is?

Insider trading involves, among other things, trading on “material nonpublic information.” Source A did not consider the information obtained from each drug-study doctor he spoke with to be material. Information is “material,” the Supreme Court has said, if “there is a substantial likelihood that a reasonable investor would consider it important in deciding” whether to trade a security.

The drug studies that Source A was hearing about were “double blind,” meaning that neither the doctors nor the patients knew who were getting the placebos and who were getting the test drug. In addition, each doctor he contacted had access to only tiny samples of patients, and the studies were ongoing, not completed. No rational person would run out and place a trade based solely on impressions gained in a conversation with one of these very imperfectly informed doctors. So the information gained from each conversation wasn’t material.

Still, Source A says, he could learn pertinent tidbits. A conversation might have gone like this, he continues:

Analyst: Do you think your patients are getting the placebo or the test drug?

Doctor: I’m seeing rashes in nine of 12 patients, so they probably got the drug.

Analyst: Are the patients with rashes doing better?

Doctor: Yes, they seem to be.

Such a conversation, in aggregate with lots of other conversations and a wide range of other research, might add up to something compelling.

This is the so-called mosaic theory, which is the research analyst’s North Star and presumed safe harbor. The SEC has generally endorsed the mosaic theory in commentary accompanying certain rules releases. If a stock analyst collects numerous nonmaterial nuggets of information from different sources, and then adds them together, he should be okay, even if the agglomeration of his information becomes material. The image that emerges from the mosaic can be material, so long as no individual tile is.

Now let’s compare that with what Cohen’s indicted portfolio manager Mathew Martoma is accused of doing. Through an expert network Martoma met Sidney Gilman, a renowned neurologist who was also the chairman of the safety monitoring committee on a Phase II trial of an Alzheimer’s drug being studied by Wyeth and Elan. Gilman, now 80, came to regard Martoma as a friend and pupil, according to the SEC. In July 2008, Gilman emailed Martoma a PowerPoint presentation of the study’s final results 12 days before Gilman was to present them for the first time at a professional conference, Gilman has told the government. Martoma began dumping his position in Wyeth and Elan shortly after Gilman sent him the PowerPoint.

“That’s the worst thing I’ve ever seen,” says Source A. “That’s different from, ‘The patients look like they’re doing well now.’ It doesn’t matter what doctors are telling you before the card is flipped. That’s not inside information. Martoma played blackjack with the cards exposed.” (Martoma has pleaded not guilty and is scheduled to go to trial in November. Gilman is cooperating with the government in exchange for not being charged.)

Still, while everyone seems to agree that what Martoma is charged with is illegal insider trading, not everyone’s sure that what Source A used to do was fine and dandy. Source B, the executive at a different hedge fund, is uneasy when told of those facts.

“Talking to scientists on a clinical trial about what’s going on before it’s been made public?” he asks skeptically. “And paying them for the information? That’s very, very gray. I’d be uncomfortable with that, but I can’t tell you it’s definitively wrong.”

Insider trading is a serious crime. Rajaratnam got 11 years for it in September 2011. How, then, can there be so much confusion about what it is? Isn’t it defined in the insider-trading statute?

That’s where all the problems begin. There is no insider-trading statute.

Most modern-day, insider-trading prosecutions are brought under the general federal statute forbidding securities fraud. Fraud involves lying, deception, or trickery. But most stock sales occur over exchanges, where the buyer and seller never meet, let alone mislead each other. Ordinarily, silence can’t be fraud. So the mere fact that the buyer of a stock knows something important that the seller doesn’t is not enough to make him guilty of insider trading.

Our contemporary notion of insider trading began taking shape in 1961. That year the U.S. Securities and Exchange Commission concluded that since corporate officers and directors owe a special duty of trust and confidence — a “fiduciary” duty — to their shareholders, they do commit fraud if they buy company stock from one of their shareholders, or sell company stock to someone (who thereby becomes one of their shareholders), based on material nonpublic information. Such trades are now known as “classic” insider trading. Furthermore, if the corporate insider tips someone outside the corporation to inside information so that he can trade on it, the tippee may be guilty too.

Gradually, the SEC and federal judges extended the concept of insider trading to reach some situations in which not only was the trader not a corporate insider, but his information hadn’t ever come from any corporate insider. The case of the former Wall Street Journal columnist R. Foster Winans is a famous illustration. For several months in 1983, Winans would regularly leak his “Heard on the Street” columns to a couple of Kidder Peabody brokers just before they were published. The brokers traded on the stocks mentioned in the columns and then shared the profits with Winans. Winans was not himself a corporate insider and none of the information he published was illegally leaked to him by corporate insiders. Nevertheless, he was charged with insider trading on the theory that he’d breached his fiduciary duty to his employer, the Journal, which forbade its journalists from trading in the companies they were writing about. (This became known as the misappropriation theory of insider trading, because Winans misappropriated information that belonged to his employer.) Though Winans was, in the end, convicted on a different theory of wrongdoing, the U.S. Supreme Court explicitly accepted the misappropriation theory in a different prosecution in 1997.

The anomaly of Winans’s situation was that, while he was forbidden from trading on the information contained in the columns he wrote, the Journal itself was theoretically free to do so, since it couldn’t violate a duty to itself. In fact, many journalism organizations effectively do trade on the market-moving information they gather — or, more precisely, they sell it to traders so that they can do so.

That’s what brought Thomson Reuters unwanted publicity this past June. As the Journal and CNBC then reported, Thomson Reuters has for years paid the University of Michigan more than $1 million annually to distribute the results of a market-moving consumer sentiment survey the university conducts. The university releases its findings to the public at 10 a.m. every other Friday. But Thomson Reuters, with the university’s blessing, releases those figures to its paying subscribers five minutes earlier, at 9:55 a.m., so that they can get a trading jump on the nonpaying public. In addition, until July of this year, Thomson Reuters also released the study findings two seconds earlier still, at 9:54:58 a.m., in machine-readable form, to certain super-premium subscribers — hedge funds that specialize in high-speed trading. The funds paid $5,000 per month for this extra headstart, plus $1,025 per month for the hookup fee, according to the Journal. In the two-second window they could easily trade hundreds of thousands of shares, racking up sure-thing profits worth hundreds of thousands of dollars.

In July, Thomson Reuters suspended the advantage it sold to high-speed traders at the behest of the New York attorney general, who is investigating whether it violated state law. But no one alleges that Thomson Reuters’ practices amount to insider trading. (Thomson Reuters denies wrongdoing and says its distribution policies were fully disclosed.)

All this focus on arcane “fiduciary duties” leads to weird loopholes, anomalies, and ambiguities — another source of gray pervading the insider-trading field. This scholasticism may have reached a comic apogee in the case of a Ukrainian national named Oleksandr Dorozhko, who in 2007 allegedly hacked into the servers of Thomson Financial over the Internet, stole quarterly earnings figures for a health care company hours before its announcement, shorted the stock, and made $286,000 overnight.

That’s got to be insider trading, right?

Not necessarily, explains Donna Nagy, a law professor at the University of Indiana. The hacker owed no fiduciary duty to either Thomson or the health care company, she points out, so he wasn’t defrauding either in the usual sense. In light of that fact, the U.S. Court of Appeals for the Second Circuit decided in 2009 that the trial-level judge would have to explore the precise nature of the hack Dorozhko allegedly used to break into the servers. If he misrepresented his identity, for instance, then he defrauded the companies. But if he merely “exploited a weakness” in the “electronic code,” it wasn’t fraud, and the case would have to be dismissed. (After that ruling, Dorozhko stopped cooperating with his lawyer and effectively defaulted.)

Isn’t it a major problem having such fuzzy parameters for such a serious crime?

“Yes,” says Stephen Bainbridge, a professor at the UCLA School of Law and author of a treatise on insider trading. “But it’s a problem the SEC and Congress have deliberately created and preserved.” At least twice, he notes, in 1984 and 1988, Congress and the SEC mulled over whether they should write a statute sharply defining the crime but opted not to. “They decided that creating a definition would be a blueprint for fraud,” Bainbridge explains. “It would allow clever Wall Street types to figure out loopholes — conduct that wasn’t covered through oversight.” By keeping the law fuzzy, Congress could “preserve wiggle room for the SEC to respond to new types of fraud.”

But can’t we at least discard all these vexing, ethereal fiduciary duties? Why not just outlaw any trading on material nonpublic information by anyone, period?

In 1968 the U.S. Court of Appeals for the Second Circuit — the appeals court that hears more insider-trading cases than any other because of its jurisdiction over New York and Connecticut — seemed to do just that. In a landmark case involving the mining company Texas Gulf Sulphur, whose insiders bought stock before their company announced that it had discovered a rich new ore deposit, the court said flatly: “Anyone in possession of material inside information must either disclose it to the investing public or … abstain from trading.”

This became known as the parity-of-information view, because it focused on whether the parties to the trade had equal access to information.

But in a pair of cases decided in the early 1980s, the Supreme Court squarely rejected the Second Circuit’s broad approach. It did so in part out of fealty to the language of the relevant statute, which was about “fraud.” But policy concerns also motivated the court, as became quite explicit in the second ruling of the pair, Dirks v. Securities and Exchange Commission. That case, decided in 1983, proved something of a Magna Carta for stock analysts.

The facts of the case were odd. Ronald Secrist, a former officer of a public life insurance company, discovered that his former company was committing a massive accounting fraud. Secrist asked Raymond Dirks, a broker-dealer, to expose the fraud. Dirks contacted the Wall Street Journal but couldn’t persuade it to go with a story. Simultaneously, Dirks counseled his clients to dump their stock in the insurer or to short it (i.e., bet on it to go down in value). The stock plummeted, authorities launched probes, and the insurer was, in fact, charged with fraud. But so was Dirks, for his alleged insider trading.

In a 6-3 decision, Justice Lewis Powell Jr., writing for the majority, concluded that since Secrist obtained no personal benefit from tipping Dirks to the fraud — he did it for the public good — Secrist hadn’t breached any duty to his company. And if the tipper hadn’t breached any duty, the court found, neither had his tippee, Dirks.

Punishing a person “solely because [he] knowingly receives material nonpublic information from an insider and trades on it could have an inhibiting influence on the role of market analysts,” wrote Justice Powell for the majority. “Market efficiency in pricing is significantly enhanced by [analysts’] initiatives to ferret out and analyze information,” he continued, “and thus the analyst’s work redounds to the benefit of all investors.”

The message was that if we want to ensure that stocks are valued accurately — promoting “market efficiency” — we must give stock analysts an incentive to do extensive, critical research of companies. The fact that these analysts gain informational advantages over others in the market is not, then, necessarily illegal. Sometimes, in fact, it benefits society.

The Dirks ruling seemed to drive a stake through the heart of the parity-of-information view of insider trading. Yet the latter refused to die.

“The SEC was never happy with the way the Supreme Court defined insider trading,” says professor Bainbridge of UCLA. It continued to fight for its favored view — “If you have material information, you can’t trade,” as he puts it — by bringing suits that aggressively interpreted the law and issuing rules that tried to expand the definition.

As a result, says Yale Law School professor Jonathan Macey, today “there are two laws of insider trading.” There’s the law the Supreme Court has laid down and the law the SEC embraces. “If you’re advising clients, you have to know both,” he explains, because most clients don’t want to incur the attorney fees and bad press of having to defend an SEC action, even if they might win it in the courts five years down the road.

In the wake of Dirks there followed a period in which certain powerful stock analysts enjoyed a privileged position in the investing firmament. By the late 1990s, a CEO could, with impunity, meet with one of these analysts and openly ladle out material nonpublic information, knowing the analyst would turn around and give it to his clients so that they could get rich with it. The practice was known as selective disclosure, and it was widely assumed to be lawful because of the Dirks ruling, in which, remember, the court said that both the corporate insider and his tippee were protected if the insider received no “personal gain” from leaking inside information.

The theory here, explains Harvey Goldschmid, a former SEC commissioner who is now a professor at Columbia Law School, was that “the CEO was giving the information not for his personal benefit, but for corporate goodwill.” He was seeking to ensure better stock valuations, mitigate volatility, and so on.

Yet the conduct still walked, talked, and quacked like insider trading. In addition, there was concern that the C-suite personnel were, in effect, “buying off analysts and perverting their willingness to criticize and dig,” as Goldschmid says. Basically, the analysts wouldn’t want to risk losing access to inside information by issuing dour reports and buzzkilling “sell” recommendations.

Though some within the SEC wanted to bring insider-trading charges against selective disclosers, according to Goldschmid, who was the commission’s general counsel at the time, the commission in the end opted for a less combative approach. In Regulation FD (for “fair disclosure”), which took effect in October 2000, it banned selective disclosure, decreeing that if C-suite officers were going to disclose material nonpublic information they had to do so in a public forum.

Reg FD leveled the playing field for research analysts and turbocharged demand for their services. It also gave researchers some guidance about how to lawfully ply their trade, because the commentary accompanying it officially endorsed the “mosaic theory.”

A company “is not prohibited from disclosing a non-material piece of information to an analyst,” the SEC wrote at the time, “even if, unbeknownst to the [company], that information helps the analyst complete a ‘mosaic’ of information that, taken together, is material.” It went on: “Analysts can provide a valuable service in sifting through and extracting information that would not be significant to the ordinary investor to reach material conclusions. We do not intend … to discourage this sort of activity.”

The devil being in the details, however, researchers and regulators soon developed differing notions about precisely what the mosaic theory was meant to protect.

Suppose someone wants to get a sense of a company’s upcoming quarterly earnings. Let’s approach the question in steps, beginning with the most clearly innocuous information-gathering techniques and gradually moving up the ladder to dicier approaches.

There’s nothing conceivably wrong, for instance, with an analyst camping out at the port of Newark, for instance, and counting how many Toyotas are offloaded from ships. There are “channel-checking” firms that engage in research like this for analysts.

Similarly, it’s unimpeachably clean to send “mall walkers” to key shopping centers on Black Friday, the day after Thanksgiving, to monitor traffic at a number of Abercrombie & Fitch or Gap stores.

It’s also often possible for analysts to chat with individual store managers about how sales are doing. “Say I’m trying to estimate McDonald’s sales,” says Source B. “I could go find 20 representative stores,” he says. He could send a researcher to talk to store managers at each. “You could interpolate sales with some reasonable degree of accuracy,” he continues. “I’m seeing this trend; it’s confirming my thesis; I think that’s a go.” For a national chain with 32,000 stores, such information can’t possibly be material, and if the analyst doesn’t pay the store managers — i.e., the manager is getting no “personal benefit” — the analyst has an additional layer of protection under Dirks.

Now let’s pose a hypothetical. Suppose it were possible to talk to all 2,000 store managers in a chain, giving the portfolio manager granular data about 100% of the companies’ retail sales. Would that still be protected under the mosaic theory? As long as all the information came from independent sources, says Source B, it should be okay. “That’s mosaic theory,” he says.

But Donald Langevoort, a law professor at Georgetown University Law Center and a former SEC staffer, is dubious. “Two thousand interviews with 2,000 store managers? Those insiders have given you collectively the biggest tip in the world. I’d be happy to take that case before a jury [as an SEC enforcement lawyer], especially if each manager had been given something of value, like theater tickets.”

Of course it’s unrealistic to interview 2,000 store managers, so let’s ratchet up the stakes a notch. What if the analyst speaks to a district manager, whose region accounts for 10% of a company’s total sales? Or two district managers? Or six?

Five years ago some analysts were certainly speaking to such insiders. Today, on the other hand — and certainly since Rajaratnam’s arrest — many hedge funds and expert-network firms forbid analysts from speaking to midlevel corporate insiders because the practice goes too close to the line. In addition, by paying insiders to violate their fiduciary duties to their corporations, analysts subject their funds to the risk of civil suit by the corporation being researched for “tortious interference” with the district managers’ contracts with the company. (In November 2010 the Tampa-based research firm Retail Intelligence Group was sued by discounter Big Lots Inc. on this theory. The case was settled.)

Still, there are other ways to get information of nearly equal quality. Public companies often have big customers, suppliers, distributors, or franchisees that are private companies and whose CEOs are willing to speak to analysts. Technology companies, with their hundreds of components and lengthy supply chains, are especially vulnerable to informational seepage. Analysts sometimes make contacts within the Asian factories to which Western companies outsource their manufacturing functions.

Suppose, then, that an analyst speaks to a franchisee who runs 200 Wendy’s restaurants? Is that still protected by the mosaic theory, or is this “tile” of information too big and revealing? No one knows. Some compliance officers use 5% of revenues as a rule-of-thumb cutoff. Under that rule, the hypothetical Wendy’s franchisee would probably be fair game, since Wendy’s now has more than 6,600 locations. But how many additional franchisees can the analyst approach? A few dozen, say, with aggregate insight into 60% of sales? No one knows.

To the reader, playing it safe may seem like the obvious default answer to all these questions. Yet hedge fund managers don’t see things that way. If a fund forgoes a lawful research technique, its investment advice won’t be as good as it could have been, nor as good as its competitors’.

“You’re acting as a fiduciary for your investors,” stresses Source B. “If you think there’s value there, and it’s legal, aren’t you obligated to use it? You want to go into a fistfight with one arm tied behind your back?”

This story is from the September 2, 2013 issue of Fortune.