Having health insurance is supposed to save you money on your prescriptions. But increasingly, consumers are finding that isn’t the case.

Patrik Swanljung found this out when he went to fill a prescription for a generic cholesterol drug. In May, Swanljung handed his Medicare prescription card to the pharmacist at his local Walgreens and was told that he owed $83.94 for a three-month supply.

Alarmed at that price, Swanljung went online and found Blink Health, a start-up, offering the same drug — generic Crestor — for $45.89.

It had struck a better deal than did his insurer, UnitedHealthcare. “It’s completely ridiculous,” said Swanljung, 72, who lives in Anacortes, Washington.

In an era when drug prices have ignited public outrage and insurers are requiring consumers to shoulder more of the costs, people are shocked to discover they can sometimes get better deals than their own insurers. Behind the seemingly simple act of buying a bottle of pills, a host of players — drug companies, pharmacies, insurers and pharmacy benefit managers — are taking a cut of the profits, even as consumers are left to fend for themselves, critics say.

Although there are no nationwide figures to track how often consumers could have gotten a better deal on their own, one industry expert estimated that up to 10 percent of drug transactions involve such situations. If true nationwide, that figure could total as many as 400 million prescriptions a year. The system has become so complex that “there’s no chance that a consumer can figure it out without help,” said the expert, Michael Rea, chief executive of Rx Savings Solutions, whose company is paid by employers to help them lower workers’ drug costs.

Pharmacy benefit managers, the companies that deal with drug benefits on behalf of insurers, often negotiate better prices for consumers, particularly for brand-name medications, Rea said, but that’s not necessarily true for some generic drugs. Insurers’ clients are frequently employers overseeing large numbers of workers, and the companies are focused on overall costs. So when insurers seek deals for generic drugs, they do so in batches, reaching agreements for groups of different drugs rather than getting the lowest price on every drug.

As a result of these complicated layers of negotiation, which are not made public, different insurers end up paying different prices for individual drugs. Further compounding confusion for consumers, some insurers require a set co-payment for each prescription — say, $15 or $20 — even when the insurer reimburses the pharmacy at a much cheaper rate.

Several companies have emerged to capitalize on consumer anger over the confusing variations in price. The players include not only Blink Health and its better-known competitor GoodRx, but also veteran businesses like the benefit manager Express Scripts, which recently helped to start a subsidiary aimed at cash-paying consumers. Amazon, the online behemoth, is also said to be considering whether to join the fray.

Last Sunday, CVS Health announced plans to merge with health insurer Aetna, a move that would create a corporate behemoth that many have said would have little incentive to serve the needs of regular people. Some consumers say their experience with CVS already demonstrates how easy it is to fall through the cracks. In one case, a customer whose plan was managed by CVS Caremark, the drug benefit manager, would have had to pay more for a drug through her plan at a CVS than what she ended up paying at the same store, with a coupon from GoodRx.

Representatives for insurers and pharmacy benefit managers say cases like Swanljung’s are “outliers.” “There are three to four billion generic scripts written a year, and in the vast majority of cases, they are going to get a better deal by using insurance,” said Mark Merritt, chief executive of the Pharmaceutical Care Management Association, which represents benefit managers.

A spokesman for UnitedHealthcare, Swanljung’s insurer, noted that while Swanljung got a lower price for generic Crestor by using Blink Health, he also takes four other prescriptions, for which he got a better deal through his insurance. (Swanljung gave UnitedHealthcare permission to discuss his situation.) Having insurance is clearly valuable, said the spokesman, Matt Burns. In addition, the co-payment for generic Crestor, also called rosuvastatin, in Swanljung’s plan is set to decrease significantly in January, in large part because the price of the drug has dropped this year.

Consumers also may face penalties if they don’t use their insurance and pay cash to save money. In many cases, insurers won’t let them apply those purchases to a deductible or out-of-pocket spending maximum.

Still, many find that leaving their prescription card at home is worth it. Some have found a better deal even at pharmacies that are owned by their drug plan, like CVS.

Susan Thomson, 55, a university lecturer who lives in Summit, New Jersey, is covered by a high-deductible plan through her former employer. Her drug benefits are managed by CVS Caremark, a subsidiary of CVS Health. For at least a decade, she’s been using a prescription lotion called sulfacetamide sodium to treat rosacea, a skin condition.

Last year, each time she filled her prescription at a CVS pharmacy, she paid $75.07. Checking the CVS Caremark website this year, she learned that the cost had gone up to $99.03 (or $81.51 if she used CVS’s mail order service).

Investigating further, she found that GoodRx offered the same prescription at the same drugstore for $75.57, without her insurance. The prices were even lower at other pharmacies.

“It just doesn’t seem right,” she said. “I just feel that the pharmaceutical industry and health care industry are pulling these numbers out of thin air.”

Michael DeAngelis, a spokesman for CVS, did not dispute the details of Thomson’s experience, but said it is rare and attributed the price disparity to her high-deductible plan. Because consumers are responsible for their costs in those plans until they hit their deductible, DeAngelis said it would take them longer to reach it and they might end up spending more in the long run.

Prices can also vary widely from month to month when consumers pay cash, he said.

Drug-discount cards have been around for decades, and retailers like Walmart have also offered cheap generic drug programs, but both were mainly used by people without insurance.

That is changing. Even as more Americans have health insurance since the Affordable Care Act was passed, insurers are increasingly asking consumers to pay a larger share of their costs. In 2016, about five million people in Medicare hit a stage in which they had to pick up a greater share of their expenses.

Reporters at ProPublica and The New York Times examined whether they could get better prices on 100 of the most prescribed drugs, identified by GoodRx, without using their insurance. ProPublica’s prescription claims are managed by OptumRx, a large pharmacy benefit manager owned by UnitedHealth Group; The Times’s medication coverage for reporters is managed by Express Scripts.

Both reporters found lower prices on GoodRx for at least 40 drugs on the list (many were drugs that can be purchased for $4 at Walmart, without any coupon).

Blink Health also sometimes beat the insurance out-of-pocket costs, but less often than GoodRx. Blink Health recently suffered a series of setbacks when two of the largest drugstore chains, CVS and Walgreens, stopped accepting its discounts, along with a grocery chain, Publix. In November, Blink Health sued its pharmacy benefit manager, which negotiates its prices, claiming that the company, MedImpact, had violated their agreement. MedImpact has not yet formally responded to the allegations in federal court in New York.

GoodRx, a private company founded in 2010, displays the deals it has with nine pharmacy benefit managers, each offering different prices for different drugs.

“We said, let’s see if we can gather all these prices and see if we can exploit the variation in these contracts,” said Doug Hirsch, GoodRx’s co-founder and co-chief executive, “to see if we can provide better value.”

Dr. Brad Wainer, a family-practice doctor in Berwyn, Illinois, said he frequently shows patients their options on GoodRx to see if they can get a better price. “Most of them don’t believe me until they go and they find it out for themselves,” he said.

Consumers may also pay more if they are covered by plans that require them to pay a set co-payment, no matter the cash price. In some of those cases, the insurers require the pharmacies to send them the difference between what they collect from the consumer and what the insurers have agreed to reimburse the pharmacies.

After a New Orleans television station, WVUE, reported last year on this practice, known as a clawback, lawyers across the country filed lawsuits accusing the insurers — including Cigna, Humana and UnitedHealthcare — of overcharging consumers. The companies are contesting the suits.

Several independent pharmacists said there might be safety issues if consumers buy drugs at different pharmacies. If those prescriptions are filled without an insurance card, pharmacy systems may not catch dangerous drug interactions. “That, to me, is a recipe for disaster,” said Craig Seither, who owns Fort Thomas Drug Center in Fort Thomas, Kentucky.

Mary Furman, a retired medical social worker in Charlotte, North Carolina, takes the drug celecoxib, the generic version of Celebrex, to treat her rheumatoid arthritis. When she went to fill a 90-day prescription in April, her pharmacy told her she would owe $96.89 if she used her Medicare plan, offered by SilverScript, run by CVS Health.

Then the pharmacy offered her a deal — $72.25 if she paid cash, a price the worker said was the same the pharmacy would offer any customer. “I was flabbergasted,” said Furman, who is 72.

Furman took the deal, and afterward, her husband, Nelson, called SilverScript to report what happened. The representative told Nelson Furman he was “not surprised.”

The couple then reported the experience to a company hired by Medicare to investigate fraud, but a representative encouraged her to contact the health plan again.

After reporters sent details of Furman’s case to CVS, Nelson Furman said they received a call from the SilverScript president. DeAngelis, the CVS spokesman, blamed the pharmacy for charging the couple more than what their share should have been using their insurance. (Medicare rules require that consumers always get the lower price of their set co-payment and a pharmacy’s cash price.)

Now the Furmans are looking at drug coverage for next year, and once again, they see huge variation in prices for that drug and others.

“The prices are all over the map,” Nelson Furman said.