Following the "letter of the law" means following the rules — especially laws — perfectly, without leaving any room for leverage. This is different from following the "spirit of the law," which means that someone is taking the law and interpreting it for practical purposes. "Letter of the law" is an English idiom that means that someone is heeding laws in the strictest fashion possible. In most cases, this is rarely done, since there are so many laws in society with extremely minute details and qualifications attached to them that it would be nearly impossible to do this on a broad basis.
When someone says a word or a small phrase in the English language that has an accepted meaning different than the literal definitions of the words themselves, he or she is using an idiom. An idiom generally originates from one specific circumstance but evolves so that it may be used in several different situations. These idioms provide a way for those speaking to add color and impact to their conversations with others. One such idiom referring to a strict interpretation of a rule or law is the phrase "letter of the law."
This phrase generally implies that a law is being followed without any room for loose or lenient interpretation. This can refer to a person who has to abide by the laws or those who administer them. As a result, consider the sentence, "They really stuck to the letter of the law in this case, which is why the punishment is so severe."
The opposite of this idiomatic expression is the phrase "spirit of the law." Someone following the "spirit of the law" is essentially abiding by the law in question, even if he or she may not be completely following it with the utmost faithfulness. It is a more liberal interpretation of a law, and it is often used when certain laws have become somewhat dated. For example, someone might say, "The letter of the law says that he has to pay back the damages, but that judge is likely going to follow the spirit of the law and let it slide."
Contrasting attitudes toward the laws are at the heart of the differences between those two phrases. Following the "letter of the law" means that there is no room for argument. Those who follow the "spirit of the law" are much more likely to be lenient.