There are only four specific uses for a comma according to R.L. Trask in his Guide to Punctuation: Listing, Joining, Gapping, and Bracketing. If the comma you want to use doesn't fit into any of those categories then the comma is the wrong choice of punctuation. This is my interpretation and summary of Trask's section on commas.
These are the commas we're most familiar with.
Apples, oranges, grapes, and pears
The serial (or "Oxford") comma (the comma before "and") is not compulsory, but it does help to avoid ambiguity, such as in the infamous example:
I'd like to thank my parents, Ayn Rand and God.
It is only important to be consistent in your choice to use, or not use, the serial comma. If one of your sentences contains an ambiguity that requires a serial comma, you must edit every other sentence that contains a list where the serial comma has been omitted.
A joining comma joins two sentences together with a connecting word such as and, or, but, while, or yet.
We will wait in the car, but Sarah will return home to pack.
The sentence above would require a semi-colon rather than a comma without the use of the connecting word "but".
The gapping comma is used to indicate that (repeated) words have been left out of a sentence.
The Cambridge students decided to play chess; the Oxford students, cricket.
The comma replaces the words "decided to play" in the sentence above.
The gapping comma, like the serial comma, can be omitted if there is no ambiguity caused, and if the use or omission is consistent throughout the document.
If a portion of a sentence can be placed in brackets it can also be placed between commas for clarity. And commas are less intrusive than brackets. Another way to determine whether bracketing commas are required is to read the sentence without the phrase in question. Use commas if the sentence is still complete without the phrase. But again, as with the gapping comma, bracketing commas can be omitted if doing so doesn't affect the clarity of the sentence or cause ambiguity.
Sam initially wanted a coffee, but, after having to walk all the way to the cafe, decided on a cold drink instead.
"[A]fter having to walk all the way to the cafe" is extra information that can be removed from the sentence and it will still make sense.
Bracketing commas are always used in pairs, unless the phrase falls at the beginning or end of a sentence. It is better to leave a comma off completely than to use only one of a bracketing pair in the middle of a sentence. A very common error in a sentence like the example above is to omit the first bracketing comma after "but".
Once you wrap your head around the four uses of the comma it becomes much simpler to deal with this most common of punctuation marks.
This article was first published on The Blood-Red Pencil in July 2008. © Elsa Neal
R. L. Trask was a Professor of Linguistics at the University of Sussex and highly regarded as both a lecturer and the author of books such as Mind the Gaffe! and Say What You Mean : The Superior Person's Guide to Precise and Lucid English Usage. Larry Trask's combined American and British perspective on language usage is particularly useful in our global era. He was born in the United States in 1944, and lived in England from 1970 to his death in 2004.