1. Joining two independent clauses:
* Use a comma before "but": If "but" joins two complete sentences, a comma is needed.
* Example: "The weather was terrible, but we still had fun."
2. Introducing a contrasting phrase or clause:
* Use a comma before "but": If "but" introduces a contrasting element, a comma is generally needed.
* Example: "She was tired, but she still wanted to go to the party."
3. Part of a compound preposition or conjunction:
* No comma before "but": If "but" is part of a phrase like "nothing but" or "all but", a comma is not needed.
* Example: "There was nothing but sand as far as the eye could see."
4. Starting a sentence:
* No comma before "but": If "but" starts a sentence, no comma is needed.
* Example: "But she was already gone."
In short:
* Use a comma before "but" when it connects two independent clauses or introduces a contrasting element.
* Don't use a comma before "but" when it's part of a compound preposition or conjunction or when it starts a sentence.