Commas indicate a small separation, semi-colons are a medium separation and periods are a large separation. Commas help people know how words are grouped together and connected or not connected.
Grammar is complicated and frequently has exceptions. These tips will help you use commas correctly most of the time, but they're not exact or complete.
This article assumes you already understand clauses, phrases and parts of speech (including coordinating and subordinating conjunctions). I explain those, and more, in English Language, Analysis & Grammar.
Commas Between Clauses
Commas are sometimes used to separate clauses which are joined with a conjunction. To join two clauses with no conjunction, use a semi-colon. There are four common patterns:
Usually put a comma before a coordinating conjunction which joines two clauses:
Commas can be tricky for some people, but reading a guide can help people who are interested in learning.
But coordinate clauses don't need a comma if they're simple enough:
I like cats and I like dogs.
You don't usually use a comma for a subordinating conjunction:
I want soup because it's warm.
But when the subordinate clause is before the main clause, then you need a comma between clauses:
If you want to stay warm, bring a jacket.
Commas are common when words aren't in the standard order.
Commas Between Phrases
Don't use a comma for a coordinating conjunction joining two phrases. Example:
I like cats and dogs.
Here "and" joins the noun-phrases "cats" and "dogs". There aren't two clauses, so don't use a comma.
Commas are used for lists of phrases. A list means three or more phrases in a row of the same type, like this:
I like cats, dogs, mice [optional comma] and birds.
As a general rule of thumb, leave out unnecessary things when writing. But another rule of thumb is to be clear and avoid anything confusing. So if the optional comma helps prevent confusion, it's good, but otherwise it's bad. The optional comma generally helps when list items are long or contain conjunctions like "and" or "or".
With lists, you can see it like putting a comma where you leave out an "and". It's like you shortened "I like cats and dogs and mice and birds".
Adjectives (and adverbs) can be treated like a list, even if there are only two and there's no conjunction. For example:
I bought a big, expensive car.
This basically means "big and expensive car".
Don't use commas where you couldn't say "and". E.g.:
I bought a red sports car.
You wouldn't say "a red and sports car". That's wrong, so there's no comma here. You can also consider if changing the order works: you can say "an expensive, big car" (it's just a little awkward) but you can't say "a sports, red car".
"Sports" is grouped more tightly with "car" than "red" is. It has a stronger connection. That means "sports" and "red" aren't peers or equals. They aren't really forming a list together because they aren't fully the same type of thing. And if they aren't part of the same list, that takes away the reason to use a comma.
Commas for Asides
Commas often go around optional or inessential parts of sentences, including non-restrictive modifiers. They're sorta like a weaker or milder version of parentheses.
Commas can set aside a clause:
Monday, which is a holiday, is the only day I'm available.
Or a phrase:
Joe, on the other hand, is hillarious.
Or a single word:
In this case, however, I think he's lying.
Commas are commonly used with introductory phrases:
By the way, I like food.
This is similar to using commas in the middle of the sentence, but at the start or end of a sentence you can separate some words with only one comma. Here's a comma for a phrase at the end of a sentence:
Cars are useful, by the way.
Commas are also common with appositives (two or more noun phrases in a row):
The insect, a cockroach, crawled on my food.
Note that the words "a cockroach" could be deleted from the sentence and it'd still make sense.