In criminal law, the principle of legality is designed to guarantee the primacy of the law in criminal procedure, so that neither state prosecution nor defendants are exposed to arbitrary bias.
The principle of legality assures that no defendant may be punished arbitrarily or retroactively by the state. This means that a person cannot be convicted of a crime that has never been publicly announced, nor by a law that is exessively unclear, nor by a penal law that is passed retroactively to criminalize an action that was not criminal at the time it occurred. It requires judges to always lean in favor of the defendant when they interpret statutes, and forbids pronunciation of guilt without a clear and reasonable justification of this sentence.
On the other hand, the principle of legality also holds that no person is to be superior to the law. This means that ignorance of a law is almost never recognized as a legitimate defense, except in the very rare case of Mistake Of Law. If a law is clearly composed and thoroughly promulgated then all citizens are bound by it, whether or not they have personal knowledge of the law. Ignorance of a law may mitigate severity of guilt, perhaps reducing the degree of mens rea from "knowingly" committing a crime to "negligently" committing a crime, but criminal law in the United States holds that ignorance almost never equals innocence. The principle of legality holds that it is not the defendant's personal knowledge that determines what he can and cannot do, but the law of the land.