Before I get into the post, let me preface this by saying that there are no hard-and-fast rules when it comes to using that or which; however these are some good guidelines that are becoming widely accepted as the rules to follow. So while you technically might not be incorrect if you go against the below information, adopting these guidelines can help eliminate any confusion in your work.
Unless you’re talking about a person, using that or which depends on whether or not you’re introducing a restrictive (also known as an essential or defining) or nonrestrictive (also known as a nonessential or nondefining) clause.
Restrictive clauses contain necessary information for the sentence. If you remove the information in the clause changes the meaning of the sentence or makes it ambiguous, then it is a restrictive clause. Restrictive clauses are NOT separated or surrounded by commas. When introducing a restrictive clause you use that unless you’re talking about a person or named animal, in which case you’d use who(m).
Tom doesn’t read books that are about talking animals. “That are about talking animals” is a restrictive clause because without it, the meaning of the sentence changes.
The car that has a crack in the windshield is mine. “That has a crack in the windshield” is a restrictive clause as it’s helping to define which vehicle is the subject’s. If there wasn’t any question as to which car is the subject’s (making the information about the windshield unnecessary,) then the restrictive clause could become nonrestrictive by being introduced with which and being separated by commas.
Nonrestrictive clauses contain unnecessary or supplemental information for the sentence. If you remove the information in the clause and the meaning of the sentence stays the same, then it is a nonrestrictive clause. Nonrestrictive clauses are introduced or separated by commas. When introducing a nonrestrictive clause you use which unless you’re talking about a person or named animal, in which case you’d use who(m).
The Grand Canyon, which was formed over millions of years, is a popular tourist destination. “Which was formed over millions of years” is a nonrestrictive clause as the information it provides is unnecessary for the sentence. The clause can be removed and the sentence would maintain its original meaning. Also note that the clause is separated by commas.
Susan refuses to drink soda, which contain too much sugar for her. “Which contain too much sugar for her” is the nonrestrictive clause because it contains information unnecessary to the sentence.
Special note: whenever you’re talking about a person or a named animal, you should use who(m). While some argue that you can use that when talking about a person with a restrictive clause, it’s more polite to use who. Unless you’d like to dehumanize the person, who should be used regardless of the kind of clause. You can use that or who when it comes to named animals, but if the named animal is a pet or something that you have an emotional attachment to (as most named animals do) then it’s common practice to use who. Using who(m) helps to humanize the animal, which you’ve already done by naming it (so why stop.)
Barbara, who won a blue ribbon in a baking contest, is coming over today. “Who won a blue ribbon in a baking contest” is a nonrestrictive clause because without it, the sentence would still retain its original meaning. Which should never be used when talking about a person.
Jack confirmed a man who has a scar over his left eye stole his car. “Who has a scar over his left eye” is a restrictive clause because it gives necessary information about whoever stole his car. Since Jack might want to be impolite towards the car thief, he could use that instead of who, but being the polite guy he is, Jack is using who. Always use who when introducing a restrictive clause about a person unless you want to be impolite.
My dog Spot, whom I love very much, is great with kids. Even though you’re not talking about a person, you’d still use whom in this case because you’re talking about a named animal of whom you hold an emotional attachment. You could use which if you wanted, and if it were an unnamed animal you would, but since you’ve already humanized the animal by naming it, you’d use who(m) to introduce related clauses. Who(m) should be used to introduce clauses about humans and humanized/named animals.
Rare special case: Which can be used to introduce restrictive clauses only if that has already been used in the sentence.
That which doesn’t kill you makes you stronger. The grammatically correct version of this is “that that doesn’t kill you makes you stronger,” though common practice makes the original acceptable/correct.
As a general rule to follow, remember: Which is for groups and things when the information isn’t necessary, that is for groups and things when the information is necessary, and who(m) is for people and named animals no matter what.
I hope this information helped to clarify when to use which, that or who(m), but feel free to reach out or comment below if you have any additional questions.