As a native speaker of English you know exactly when and how to use them. You just can't consciously explain it. But don't worry about that. There are people who study all their lives and still can't explain it.
In a nutshell:
1. restrictive clauses - use both which and that, with which being more formal.
2. when the thing becomes known, becomes clearly identified, then only 'which' is used because we have a non-restrictive clause, BUT, this is the crucial point; it's not that it's because it's a non-restrictive clause that we have to use 'which', it's because the thing has been sufficiently described that we use 'which'.
It was named after the fact and this is the part that confused some prescriptivists into making a bad analysis and concocting another silly prescription.
Basically, the same works for people using that and who. When the person is identified, we use who. There are some other considerations that enter into it but the grammar is the same.
SIDNEY GOLDBERG ON NYT GRAMMAR: ZERO FOR THREE
1. That and which. The first charge is that the Times "consistently proves that it does not know the difference between ‘that’ and ‘which,’ greatly favoring the latter." There's only one thing he could be alluding to here: he's one of those people who believe the old nonsense about which being disallowed in what The Cambridge Grammar calls integrated relative clauses (the old-fashioned term is "restrictive" or "defining" relative clauses). Strunk and White perpetuate that myth. I've discussed it elsewhere. The notion that phrases like any book which you would want to read are ungrammatical is so utterly in conflict with the facts that you can refute it by looking in... well, any book which you would want to read. As I said before about which in integrated relatives:
As a check on just how common it is in excellent writing, I searched electronic copies of a few classic novels to find the line on which they first use which to introduce an integrated relative with which, to tell us how much of the book you would need to read before you ran into an instance:
A Christmas Carol (Dickens): 1,921 lines, first occurrence on line 217 = 11% of the way through;
Alice in Wonderland (Carroll): 1,618 lines, line 143 = 8%;
Dracula (Stoker): 9,824 lines, line 8 = less than 1%;
Lord Jim (Conrad): 8,045 lines, line 15 = 1%;
Moby Dick (Melville): 10,263 lines, line 103 = 1%;
Wuthering Heights (Bronte): 7,599 lines, line 56 = 0.736%...
Do I need to go on? No. The point is clear. On average, by the time you've read about 3% of a book by an author who knows how to write you will already have encountered an integrated relative clause beginning with which. They are fully grammatical for everyone. The copy editors are enforcing a rule which has no support at all in the literature that defines what counts as good use of the English language. Their which hunts are pointless time-wasting nonsense.
Language Log: Sidney Goldberg on NYT grammar: zero for three
Student or Learner