Use a comma before "but" when:
* It connects two independent clauses: An independent clause is a complete thought that can stand alone as a sentence.
* Example: "The weather was beautiful, but I forgot my sunglasses."
* It introduces a contrasting thought: This is especially common when the "but" introduces a surprise or unexpected element.
* Example: "I love to eat pizza, but I'm allergic to cheese."
Don't use a comma before "but" when:
* It connects two phrases or dependent clauses: A dependent clause cannot stand alone as a sentence.
* Example: "I'm going to the store, but I'm not sure what to buy." (The second part is a dependent clause.)
* It's used to emphasize a point: In these cases, the "but" is more like a conjunction than a connector of clauses.
* Example: "This isn't a big deal, but it's important to me."
In general, when you're unsure, try reading the sentence aloud. If you naturally pause before the "but," a comma is likely needed.