Rhetoric and Composition/Missing or unnecessary commas with restrictive or non-restrictive elements

What are restrictive and non-restrictive elements?
An element is a word, phrase, or clause, whose meaning either narrows the meaning of another part of the sentence (restrictive) or provides extra information (non-restrictive). Following are examples of sentences with the element in bold.
 * Non-Restrictive: The dog, which I rescued from the shelter, is named Terrance. (commas)
 * Restrictive: The dog that I rescued from the shelter is named Terrance. (no-commas)

Whether an element is restrictive or not changes the meaning of a sentence. Consider these two examples: In the first case, the author is indicating that Matthew only has one brother. The name "Alfred" is in commas to indicate it is extra information; since Matthew only has one brother, you don't need to know the name to figure out which one the sentence is talking about.
 * Matthew's brother, Alfred, arrived late last night.
 * Matthew's brother Alfred arrived late last night.

In the second case, the one without commas, the author is indicating that Matthew has at least two brothers, so we need the name to know which one we're talking about. This is called a "restrictive element" because it restricts (or limits) the meaning of the word "brother" in the sentence to Alfred.

Examples of errors with commas and restrictive or non-restrictive elements

 * The youngest puppy Tiddly is the most adorable pet I have ever seen. (There can only be one youngest puppy, so the element "Tiddly" is extra information and should be set off by commas.)
 * Out of all the bowls of soup served tonight, only the one, that has the hair in it, was sent back to the kitchen. (The element "that has the hair in it" should not be in commas, since you need this information to know which bowl was sent back to the kitchen.)

Fixing commas with restrictive or non-restrictive elements
You'll need to figure out first what the element in question is doing in the sentence. If you need it to restrict the meaning of another part of the sentence, take away the commas. If it's just there to provide extra information, put commas around it.
 * The youngest puppy, Tiddly, is the most adorable pet I have ever seen.
 * Out of all the bowls of soup served tonight, only the one that has the hair in it was sent back to the kitchen.

Tips
It's generally considered correct to use "that" for restrictive elements and "which" for non-restrictive elements.
 * The essay that won the award was authored by an international student.
 * The best essay in the class, which was authored by an international student, is on display in the English department.

Learn more about commas here.