This is called an Oxford Comma. If you are writing a list, it is optional whether or not you need to use it. Typically, more formal writing tends to use it, as it tends to keep confusion at a minimum. In your example, both examples indicate four different things, while the second example could indicate 3 or 4 things. This is where the confusion comes. If "C" and "D" are connected (like peanut butter and jelly), then you should not put a comma between them. For Example, if you are writing a list like this: "Ham Sandwich", "Turkey Sandwich", and "Peanut Butter and Jelly Sandwich", then you do not put the comma in between anything. Otherwise, put commas between all individual things.
Does this help?