Commas are one of the most problematic punctuation marks out there, but once you understand the rules to using them, then writing grammatically correct sentences becomes a whole lot easier. Here are the rules:
1. Use a comma before a coordinating conjunction (for, and, nor, but, or, yet) to join two main clauses (full sentences).
Example: I'm learning how to use commas correctly, and it's really fun!
NOT: I'm learning how to use commas correctly, it's really fun. <-- this is a comma splice
2. Use a comma to off-set unnecessary information, including introductory clauses and non-essential elements in the middle or end of sentences.
Example: Today, I'm learning how to use commas. OR I really enjoy learning about commas, which is probably weird. OR The comma, a very important punctuation mark, is a beautiful thing.
NOT: The punctuation mark, is a beautiful thing, I think. <-- this is a comma misused between the subject and verb. Commas are not to be placed between subject and its verb, a verb and its objects, or any other parts of speech that go together.
REMEMBER: To check if an element is non-essential, try to read the sentence without that element. If it is a full sentence that continues to make sense without the element, then that element is a non-essential element.
3. Use commas in a series of three or more items. The Oxford comma is placed before the conjunction at the end of the series (and, or, etc.), and while it is my personal preference, it is optional.
Example. I went to the store and bought apples, pears, and plums.
NOT: My favourite colours are green, and red. <--there are only two items in this series; therefore, no comma is needed.
4. Commas are also used when showing a dialogue.
Example: She said, "I really do love commas." OR "I really do love commas," she said with a mad gleam in her eye.
Note: The comma goes inside the quotation marks when the quotation comes first.
These are the main uses of commas. If you have any questions, please let me know!