As a general rule, "mistake of fact" can be a defense to a crime but "mistake of law" cannot. However, the difference between the two isn't always clear. And there are lots of exceptions and intricacies to the general rule that vary by state.
The difference between mistake of fact and mistake of law is often subtle. But generally, mistake of fact refers to a person's misunderstanding as to the facts of a situation. The factual misunderstanding results in the person breaking the law.
Mistake of law, on the other hand, is where a person commits an illegal act but tries to escape responsibility by claiming ignorance of the law. In other words, the person knowingly does something but doesn't know it's illegal.
As a general rule, "mistake of fact" can be a defense to a crime but "mistake of law" cannot. However, the difference between the two isn't always clear.
Here are a few examples that will hopefully clarify the distinction.
Mistake of fact at Johnny's party. On Saturday night, Johnny had an end-of-summer party. The invitation he sent out said: "When you get here, don't bother to knock. Just open the door and walk through to the backyard, where we'll be barbequing." But on the invitation, Johnny mistakenly put down his address as 13 Cypress Street when his actual address is 113 Cypress Street.
James, who had never been to Johnny's house, decided to attend the party. When he arrived, he marched up to 13 Cypress, opened the front door, and started towards the backyard. To his surprise, not only was no one home, but a burglary alarm started going off. Within minutes, police arrived and arrested James for trespassing. James will likely have a mistake-of-fact defense to the charge because he trespassed based on his mistaken—but reasonable—belief that 13 Cypress Street was Johnny's home.
Mistake of law in New Mexico. Casey, who is long-time Oregon resident and regular pot smoker, recently lost his job. Luckily, he found a new job in New Mexico. When he moved to New Mexico to start his new position, he brought a significant weed stash with him. Because recreational marijuana use is legal in Oregon, Casey figured it must be the same in New Mexico. Casey was wrong and within a week he was in a New Mexico jail on marijuana possession charges. Although Casey didn't intentionally break the law, he doesn't have a legitimate defense based on his mistaken belief that recreational marijuana use is legal in New Mexico—a mistake of law.