As Apple CEO Tim Cook deftly parried attacks on his company for avoiding paying billions in taxes before Congress Tuesday, we could be forgiven for heaving a collective sigh, part resignation and part resentment. Of course the big fish get away with tax shenanigans that the rest of us don’t. It’s one more reason to hate the IRS, after the agency’s targeting of Tea Party groups for intrusive questioning.

The Tea Party groups who suffered the IRS indignities were the little guys. While they filled out endless questionnaires, the big ones made it through the process unscathed. Karl Rove’s Crossroads GPS, the Koch brothers’ Americans for Prosperity, and Barack Obama’s Priorities USA are the ones whose tax exemptions should be challenged.

But the analogy to Apple getting away with tax murder doesn’t work. First, Apple apparently broke no laws. And second, when it comes to fighting tax evasion, the IRS actually doesn’t fry the little fish while letting the big ones swim away. The IRS has increasingly tried to go after the big fish. When they get away, it’s because there are giant-sized legal loopholes for them to swim through, not because the agency has failed or has the wrong priorities.

First, a little history from Tanina Rostain, a Georgetown law professor at work on the upcoming book Confidence Games: Lawyers, Accountants, and the Tax Shelter Industry. (Her co-author is Milton Regan Jr.) When I called Rostain, she took me back to the late 1990s, when the IRS was in disarray. The agency was under political attack from Republicans, who browbeat it in the Roth hearings, claiming that armed agents had shown up to carry out late-night raids based on false accusations. It wasn’t true, but Congress still passed a law “that handcuffed agents and slashed the budget for audits and enforcement, especially against high-income taxpayers,” as Kevin Drum recounted in the Washington Monthly. The IRS also had broader troubles. The commissioner at the time, Charles Rossotti, was charged with making it a place where callers wouldn’t always get a busy signal. “His mandate was to make the IRS customer service friendly,” Rostain says. Enforcement took a back seat—just as Congress had ordered. And for the next few years, a thousand tax shelters bloomed. Big companies and wealthy people hired accountants and lawyers who came up with all kinds of tax havens. The notion that you were a chump if you didn’t try to hide your money became the prevailing view.

By the time Rossotti left office in 2002, audit rates had plummeted and the agency was desperate for more enforcement, Rostain says. And they started to do it. The Wall Street Journalreported that in 2004, “the IRS audited nearly 200,000 high earners (people earning $100,000 or more a year), double the number audited four years earlier.”

In 2005, another IRS commissioner, Mark Everson, was promising Congress that his top priority was “working to discourage and deter non-compliance, with emphasis on corrosive activity by corporations and high-income individuals.” Everson continued:

“Attacking abusive tax shelters is the centerpiece of this effort. What is at stake is greater than many billions of dollars of lost tax revenues. Our surveys indicate that 80 percent of Americans believe it is very important for the IRS to enforce the law as applied to corporations and high-income individuals. Enforcing compliance in these sectors is critical to maintaining Americans’ faith that our system is fair. The abuses of recent years have to a very real degree strained the credibility of our tax administration system.”

Much of the time, the internal workings of the IRS are a mystery—they don’t want us to know who gets audited for what because that would make it too easy to cheat. But the agency trumpeted the audits of high earners—as well as the parade of lawyers and financial advisers who advised fraud and went to jail. “Our book stops in 2004 with a semi-happy ending,” Rostain said. “The IRS got the law firms, and the mood changed.”

The problem is that the action moved offshore. Apple set up empty subsidiary offices in Ireland because it could. Or even because it should, as a sensible way to save money, as Derek Thompson argues in the Atlantic. I wouldn’t go that far. But I take the point that Columbia law professor Michael Graetz made to me over the phone: “If you have a lot of income and a lot of good tax advice, the code is so broken that your opportunities for reducing taxes are higher than they are if you’re just earning your wages and paying your home mortgage and raising your children.” The Bush administration did get behind legislation to penalize offshore tax shelters. And Graetz argues that within its powers, the IRS’s march of enforcement has continued. For example, there’s the prosecution of a UBS banker accused of helping Americans hide money in Swiss accounts, and the $700 million fine UBS wound up paying the government to settle charges of interest-rate manipulation.

The IRS launched a big effort to go after secret offshore accounts in 2009, and since then 71 of these evaders been charged, Laura Saunders of the Wall Street Journal reported earlier this month. They are going to prison (though their average sentences are about half as long as the punishments doled out for other kinds of tax fraud). Still, liberal journalist Robert Kuttner asks this question: “If the IRS is supposedly so zealous about tax enforcement, why has it left on the table hundreds of billions of dollars in offshore tax evasion by the wealthiest?” Maybe the IRS should put more of its resources into these cases—and maybe Congress should give the agency more money for this purpose. Still, as Sen. Carl Levin has pointed out, “The universe of offshore tax cheating has become so large that no one, not even the United States government, could go after it all.”

In terms of the way the IRS treats big fish and little fish, the audit rates are generally reassuring. The chances you’ll be audited rises with your income bracket. Dennis Ventry, a law professor at the University of California at Davis, read me the numbers: The overall audit rate is about 1 percent. For incomes of over $1 million, it jumps to 9 percent, and for incomes above $10 million, it goes all the way to 27 percent.

It’s also true that people who claim the Earned Income Tax Credit—the working poor—are twice as likely to be audited than anyone else, says Ventry. (That’s down from four times as likely between 2000 to 2005.) There are also more problems with the tax returns of EITC claimants, though they may often amount less to fraud than to error or the shenanigans of the loan outfits that offer to fill out the forms in exchange for a big cut.

“Why does it seem that there’s always someone getting away with something in the tax world?” Robert W. Wood asks on Forbes. “Because there is. Wealthy people may manipulate the rules and pay less than you think they should. At the other end of the spectrum, scams may hand out earned income tax credits and bogus refunds. The fact that someone is playing the game better than you are can grate but it doesn’t mean the whole system is rigged.” It’s hard to hold those dual truths in your head at once. Especially when the IRS is getting pilloried for blowing it in the separate, but suddenly visible world of nonprofit status. But in the end, we need this agency. So try.

Emily Bazelon is a writer for Slate.