Martin Shkreli is the Internet's villain of the week. After buying and then immediately jacking up the price of a drug that treats a potentially deadly parasite, he's become a sneering meme in social media, a think-piece punching bag, and a policy springboard for presidential candidates. He gives a bad name to former hedge fund pharmaceutical CEOs everywhere.

How can that be? Drug companies and greed are supposed to go together like bankers and um, greed. Shkreli recently capitulated to the public outrage and said he'd drop his drug's price. But he hasn't backed down from his rationale for the original price hike: This is what it takes to do research, to be profitable, to be successful in his highly regulated industry.

And in a way, he's right. Long before you ever have a chance to balk at drug prices, the companies that make the medicine rack up billion-dollar tabs from research, development, and clinical trials. Insurance companies negotiate for distribution, and whittle more money away from a company's bottom line. Not to mention that without profits, investors won't invest in pharma, and drugs won't get made. So is Shkreli really an excessive rogue actor, or is he merely playing by the same rules as the rest of the pharmaceutical industry?

Drugs start in laboratories. Some scientist—at a university, government lab, or pharmaceutical company—finds a chemical compound that seems to have some effect on some malady. She or he isolates the compound and tests its effects on individual cells in petri dishes, then animals, building a case for human use. This preclinical work, called drug discovery, can take three to four years, and only about one in 1,000 compounds survive to get tested on human beings.

Human tests—called clinical trials—are the gauntlet of drug development, and have three phases. The first tests the drug for safety, the second for dosing, and the third makes sure the drug is effective enough against whatever it targets that it's worth putting on the market. Lasting anywhere from five to ten years, only about one in ten drugs survives clinical trials to market.

Time (plus scientists, plus lab space, plus equipment, plus patient recruitment, plus test after test after test) is money. A 2014 report from Tufts University Center for the Study of Drug Development found that the average cost of going from chemical compound to clinical trials to FDA-approved drug is $2.7 billion. Even drugs that fail early can cost companies millions. "There's a saying, that it costs a billion to produce the first pill, and 10 cents to produce the second," says Rachel Sachs, a fellow at the Petrie-Flom Center for Health Law Policy, Biotechnology, and Bioethics at Harvard Law School.

Pharmaceutical companies make a lot of hay about these costs, but they aren't the end-all be-all for a drug's final price. "If I’m the pricing person for something, I’m not looking at how much we spent making it," says Peter Ubel, a physician and professor of business and public policy at Duke University. "I’m looking at what I think the market will bear."

"What the market will bear" is an phrase you'll hear frequently when you start asking people about drug costs. What it means is nobody outside the company really cares how much a pharmaceutical company spent developing a drug. Markets care about a drug's perceived value.

Think about when Apple debuted the iPhone, says Ubel. "There were crazy research, development, and production costs, and they probably could have sold the thing for $10 and still made a profit," he says. But Apple figured that people would pay $500, and so that's what they charged.

Unlike Apple, or really any other business, pharmas have to negotiate their prices with insurance companies. "There’s not a really free market in the sense that we have in other industries," says Sachs. "You have the FDA imposing requirements that drive up the cost of making the drug, and insurers on the back end can often negotiate prices."

Perceived value is complicated (it's economics, after all), but for drugs it pretty much boils down to three things: How many patients the drug will treat, how many similar drugs are on the market, and how much a drug improves a patient's life. Insurance companies negotiate cheaper prices for the customer. But if the drug is only important for a few people, is the only thing that treats a disease, and can save lives outright, insurance companies don't have much bargaining power.

Daraprim, the pill Shkreli ratcheted from $13.50 to $750, treats a parasitic infection called toxoplasmosis. It's a pretty common infection, and in most people it's not harmful. However, if you have a compromised immune system—from AIDS, cancer, or a recent organ transplant—toxo can be fatal. In terms of perceived value, daraprim hits all the right chords: It treats small part of the population, it's the only toxoplasmosis drug on the market, and it saves lives. Cha-ching.

With all that in mind, here's the important question: Is Shkreli an industry outlier, or was he just unlucky enough to be found out? "There's one aspect of this that's an interesting hypothetical," says Sachs: Would the public be so outraged if he had bought a drug just before it went to market and initially sold it at an inflated price? It's not at all uncommon for bigger companies to buy biotech startups and independent labs to push drugs through the final stages of clinical trials.

"A for-profit company has the right to charge what it wants," says Ubel. "The risk is if industry looks too greedy they will invite regulation." Hillary Clinton took the invitation to tweet a teaser for plan to reform Big Pharma. The medical markets responded by dropping nearly 5 percent. So maybe Shkreli's big mistake wasn't that he was greedy, it was making his greed so visible.