The short answer: Use that for essential information and which for nonessential information, especially when commas are involved.
This is one of the most common grammar questions because the two words often look interchangeable, but they are not always doing the same job.
Quick Notes
- That usually introduces information the sentence needs to keep its meaning.
- Which usually adds extra information that can be removed without breaking the sentence.
- Which clauses are often set off with commas.
Examples
- The bike that is red is mine.
- My bike, which is red, is parked outside.
If removing the clause changes the meaning, that is usually the safer choice.
