Nonrestrictive or merely parenthetical sentence elements must be set off by commas. Do not set off restrictive elements.
Huh?
Translation: a restrictive sentence element (a clause, a phrase, or a word) restricts (i.e., defines or limits) the meaning of the word it modifies. A nonrestrictive element causes no such restriction; it adds information without limiting the meaning of the sentence.
Still confused? A looser translation: if you're questioning whether or not to enclose a phrase in commas, ask yourself whether or not the phrase in question limits or describes the noun it follows. If it limits the noun, it is restrictive. In that case, it is not enclosed in commas. If it describes but does not limit the noun, it is non-restrictive. In that case, it should be enclosed in commas.
Does all this give you a headache? Try these examples:
Non-Restrictive
The members of the faculty, who read the article, were shocked by its bad style.
The clause who read the article is set off by commas; therefore, the reader knows that all members of the faculty read the article and therefore the clause is nonrestrictive. You've probably already figured out that in the sentence --
Restrictive
The members of the faculty who read the article were shocked by its bad style.
--whoread the article restricts the members of the faculty who were shocked, and therefore needs no comma. The reader understands that not all members of the faculty read the article and that only those who read it were shocked.
Restrictive
He answered all the questions that were on geography.
--not all the questions were on geography, so that is a restrictive element (indicating that he answered only geography-related questions) and needs no comma. However, in the case of the sentence--
Non-Restrictive
He answered all the questions, which were on geography.
--all the questions were on geography, and therefore which is a nonrestrictive element (merely adding the information that "all the questions" were on geography) and necessitates a comma before it.
The question of that vs. which is related. In spoken usage, the pronoun which is used both in restrictive and non-restrictive clauses. However, many writers, in an attempt to minimize the confusion association with restrictive and non-restrictive clauses, reserve that for restrictive clauses and which (with commas) for non-restrictive clauses. Consider the sentence
The cape, which my roommate tore, is in the closet.
This sentence indicates that there is only one cape in question, and it is in the closet (the fact that it was torn and who tore it are unessential to its location, which is the main idea of the sentence). Substituting that for which, however, gives us this sentence:
The cape that my roommate tore is in the closet.
This sentence implies an abundance of capes, of which the one the roommate tore is in the closet. Therefore that my roommate tore qualifies the cape in question and must not be de-emphasized by commas.
For more information on that vs. which refer to Commonly Confused Words, available online at the Writing Center home page or in hard copy at the Writing Center. See also Strunk and White, The Elements of Style, under "Misused Words and Expressions."