Here's a breakdown:
When to use a comma before "but":
* When "but" joins two independent clauses: An independent clause is a group of words that can stand alone as a complete sentence.
* Example: *The weather was beautiful, but the beach was crowded.*
* When "but" introduces a contrasting idea: Even if the sentence doesn't have two independent clauses, a comma might still be needed if "but" introduces a contrasting idea.
* Example: *I love dogs, but I'm allergic to them.*
When to not use a comma before "but":
* When "but" joins two dependent clauses: A dependent clause needs an independent clause to make a complete sentence.
* Example: *I will go to the beach, but only if the weather is nice.*
In summary: Look for the following to determine if you need a comma:
1. Independent clauses: Are there two complete sentences being joined by "but"? If yes, use a comma.
2. Contrasting ideas: Is "but" introducing a contrasting idea, even if the sentences aren't independent? If yes, use a comma.
3. Dependent clauses: Are both parts of the sentence dependent on each other? If yes, don't use a comma.
Remember that these are general guidelines, and there can always be exceptions. If you are unsure, it's always best to consult a grammar guide or a style manual.