When should you use that and when should you use which?

According to some authorities (Williams, for example), the relative pronouns that and which may be used interchangeably.

example: The lion which rested by the river seemed well fed.

The lion that rested by the river seemed well fed.

According to other authorities (Lanham, for example), that and which have useful differences and should not be used interchangeably. They argue that which should introduce a parenthetical clause (= a nonessential or nonrestrictive clause, also called a 'free element') and that that should introduce an essential clause (= a restrictive clause).

example a: The lion, which rested by the river, seemed well fed.

example b: The lion that rested by the river seemed well fed.

In example a, commas set off the adjective clause because the sentence concerns only one lion and the thought remains complete even if the adjective clause is removed; the adjective clause is not essential, it is a free element and can be removed without changing the sentence meaning. In example b, no commas are used because the sentence concerns several lions, one of which is by the river. Here the relative pronoun that tells us to focus on a subset of the whole: that restricts the meaning of lion and is essential for understanding which lion.

Because the use of that and which as restrictive and nonrestrictive elements conveys useful information to the reader, I support the distinction.