Ignorance of the law is no excuse. That's the standard line motorists hear when they say they weren't aware of the speed limit, or gun owners hear when they say didn't know about the gun laws in the jurisdiction they happened to get arrested in. Yet that ignorance is pretty understandable in an America where just about everything is being criminalized. At the federal level alone there are now more than 4,500 separate crimes, and that's not counting the massive regulatory code, violations of which also can sometimes be punished with criminal charges.

As citizens, we're expected to know and obey all of these laws, in addition to state and local statutes and the relevant court opinions that interpret the breadth and depth of all of those laws.

But what happens when law enforcement officials don't know the law? What happens when they illegally detain, arrest, and charge you even though you've done nothing wrong? Unlike you, their ignorance doesn't result in arrest or jail. And unless the violation is pretty egregious, they're unlikely to be punished for it.

Consider the case of Brian Kelly. On May 24, 2007, Kelly was riding with a friend in the town of Carlisle, Pennsylvania. Officer David Rogers of the Carlisle Police Department pulled Kelly's friend over for speeding. Rogers told the two that the traffic stop was being recorded with a microphone attached to his uniform. Kelly, who had a video camera with him, began recording the stop as well. When Rogers returned from writing a ticket, he noticed Kelly's camera. Rogers demanded Kelly turn the camera off and hand it over to him. Kelly complied.

Rogers then returned to his car and called John Birbeck, an assistant district attorney in Cumberland County. Rogers asked Birbeck if Kelly's recording violated Pennsylvania's wiretapping law. Birbeck incorrectly told him it did. Rogers then called in back-up officers and placed Kelly under arrest. During the arrest, Rogers "bumped" (the term Kelly used in his lawsuit) Kelly, causing a staple from a rugby injury to rupture, causing Kelly's leg to bleed. Kelly spent the night in jail. He was eventually charged with a felony punishable by up to seven years in prison. Cumberland County District Attorney David Freed would later tell the Patriot-News that while he sympathized with Kelly not being aware that what he did was illegal, and that he might (graciously!) allow Kelly to plead to a misdemeanor, "Obviously, ignorance of the law is no defense."

Here's the problem: Freed was the one who was ignorant of the law. So was Birbeck. And so was Rogers. The Pennsylvania Supreme Court ruled in 1989 that recording on-duty public officials is not a violation of the state's wiretapping law because public officials have no legitimate expectation of privacy while they're on the job. The order for Kelly to stop videotaping was illegal. So was Kelly's arrest and his incarceration. Freed eventually dropped all charges.

Kelly filed a civil rights lawsuit against Rogers and the town of Carlisle. In May of last year, Federal District Court Judge Yvette Kane dismissed Kelly's suit. The reason? As a police officer, Rogers is protected by the doctrine of qualified immunity. In order to even get his case in front of a jury, Kelly has to show that Rogers (a) violated Kelly's civil rights, and (b) the rights Rogers violated have been clearly established. Even if Kelly can meet those two burdens, he must also show that Roger's actions in violating Kelly's rights were unreasonable.

So it isn't enough that the police are wrong about the law. They have to be very obviously wrong for you to collect any damages from a wrongful arrest.

Kane found that because Rogers sought advice from the local prosecutor's office it was reasonable for him to act on that advice, even if the advice happened to be wrong on the law. Moreover, Kane found that because the federal appeals courts have yet to find a specific right to make audio recordings of police, that right is not yet clearly established. Kelly is appealing.

Suing Birbeck isn't likely an option for Kelly, either. Prosecutors enjoy an even stronger protection called absolute immunity. Under absolute immunity, there is virtually nothing a prosecutor can do in the course of his job that would subject him to a lawsuit.

The contradiction couldn't be starker. Kelly, a citizen who neither works in law enforcement nor has been to law school, was arrested, jailed, and charged with a felony for not knowing that an antiquated law pertaining to wiretapping prevented him from using a wireless video camera to record a traffic stop that the police officer himself was recording. Even if Kelly had broken the law, at worst he made a recording of Rogers without Rogers' consent in addition to the recording Rogers was already making. Rogers wasn't harmed at all. And for that, Kelly could have gone to prison for seven years.

On the other hand, Freed, Birbeck and Rogers are all paid by taxpayers to know and enforce the law. Freed and Birbeck presumably went to law school, and presumably passed the Pennsylvania bar exam. Knowing the state's criminal code and the court decisions that affect it is a fairly integral part of their jobs. The harm caused by their ignorance of the law is far from insignificant: A man was wrongly arrested, detained, and jailed. His First Amendment rights were violated. And he was injured in the course of his arrest. Yet they won't be going to jail. In fact, they're unlikely to be sanctioned or punished at all.

And Kelly isn't the only person this has happened to. Last month, Allegheny County, Pennsylvania settled a lawsuit with Elijah Matheny, who was arrested and charged in 2009 for recording the police with a cell phone camera. Part of the settlement requires the Allegheny County DA's office to instruct local police that citizens in Pennsylvania have the right to record on-duty police officers.

That's a start. But it's one county, in one state. There have also been recent wiretapping arrests of citizens recording police in Maryland, New Hampshire, and Oregon, despite the fact that all three states have privacy provisions in their wiretapping laws, and that no court in the country has ruled that on-duty cops have an expectation of privacy in public spaces or while performing their official duties. The justification for those arrests is that the citizens of those states should know that antiquated laws covering the tapping of phone lines also make it illegal to record a police officer with a cell phone. But just as in Pennsylvania, it is law enforcement officials themselves who are wrong on the law. And even in the rare case where a wrongful arrest leads to a cash settlement, it's generally paid for by taxpayers, not the law enforcement officials who broke the law in the first place.

And the problem goes beyond wiretapping laws. Last month, police in Washington, D.C. detained and threatened to arrest Jerome Vorus, who photographed a traffic stop in Georgetown. D.C. Police Chief Kathy Lanier subsequently acknowledged on a radio call-in show that there's no law against photographing police in D.C., but then went on to excuse her officers' violation of the photographer's rights, explaining that cops don't like having their photos taken because "we can have our pictures end up on all sorts of websites, and that can be dangerous for us." The message to D.C. cops? Citizens are permitted to photograph you, but nothing's going to happen to you if you stop those citizens from exercising their rights.

Carlos Miller, who has documented dozens of these incidents on his Photography Is Not a Crime blog, has twice been prevented by private security and public police from taking video at a Miami Metrorail station, despite getting assurance from Metrorail Safety and Security Chief Eric Muntan that shooting non-commercial video on the train and in its stations is perfectly legal. Last month, The Washington Post catalogued numerous instances where people were arrested, detained, or warned for taking pictures or video in public despite having the law on their side. The New York Times reported similar incidents, including one where a man was prevented from taking photos at an Amtrak station for a photography competition sponsored by Amtrak.

As if all that wasn't bad enough, consider this excerpt from the Post article, describing the Vorus incident in Georgetown:

Police say they were justified in stopping him because was taking photos of the inside of the squad car. Vorus, who was 20 feet away, says he "wasn't trying to make a point or cause a scene" but was merely asserting his rights. Second District Cmdr. Matthew Klein said there is no official prohibition against photographing the interior of a squad car. But he said officers acted appropriately because they thought Vorus was escalating the situation. "They had a situation developing," Klein said. "They had to make a call."

What Klein describes as Vorus "escalating the situation" was Vorus explaining his rights to the cops. Not only are citizens expected to know all of the applicable laws, and to know how the courts have interpreted those laws, they must also know the sometimes tortured way that current law enforcement officials are applying those laws and legal decisions in the field. Police officers, on the other hand, do not have to know any of that. And even when citizens are right on the law, explaining the law and its proper application when confronted by the police can be interpreted as "escalating the situation," which then justifies detainment and possible arrest.

For the most part, the old axiom remains true. Ignorance of the law is no defense for breaking it. But there's an exception if you happen to work in law enforcement. Unfortunately for citizens, sometimes even knowledge of the law won't be enough to prevent you from getting arrested.

Radley Balko is a senior editor at Reason magazine.