When you want to give extra information that isn't really needed to understand the sentence, you use the word "which." This kind of information is called a nonessential clause, and the sentence would still make sense without it. For example, "My dog, which is very friendly, loves to play."
On the other hand, when the information is really important to the meaning of the sentence, you use "that." This is called an essential clause, and you can't remove it without changing what the sentence means. For example, "The dog that barks loudly lives next door." Here, "that barks loudly" tells us which specific dog we’re talking about.