When a comma goes before "but":
* Connecting two independent clauses: When "but" connects two complete sentences that could stand alone, a comma is needed before it.
* Example: *I wanted to go to the beach, but it was raining.*
When a comma doesn't go before "but":
* Connecting a dependent clause to an independent clause: When "but" is part of a dependent clause that cannot stand alone, no comma is needed.
* Example: *I wanted to go to the beach, but I knew it was raining.* (The part "but I knew it was raining" is a dependent clause and doesn't make sense on its own.)
* When "but" introduces a phrase: When "but" is not connecting two clauses, a comma is not needed.
* Example: *It was a beautiful day, but not for swimming.*
To determine if you need a comma, ask yourself:
* Does "but" connect two complete sentences that could stand alone? If yes, use a comma.
* Is "but" part of a dependent clause? If yes, no comma is needed.
* Is "but" introducing a phrase that isn't a clause? If yes, no comma is needed.
Tip: If you're unsure, read the sentence aloud. If there is a natural pause before "but", then a comma is likely needed.