Classes and IDs are used in HTML markup to take your styling to the next level. HTML elements can be modified with CSS and these changes would be applied to each of those specific elements present in your HTML document. By applying a Class or an ID to an element, you can target which elements should be affected by your CSS styling.
The most important question to ask yourself in deciding when to use an ID or a Class is whether you will use this attribute again. If the answer is yes, then you should define a new class. If no, an ID can be used. Id's are unique, each element can only have one ID and each page can only have one element with that specific ID. There are several reasons for this but a big one is your document will not pass HTML validation if the ID occurs more than once. These IDs also come in handy when applying JavaScript to your page as there are functions that rely upon there only being one instance of an ID. One other equally important reason for having a single ID is that IDs have special meanings to browsers. For instance, if you link to a website and add "#ID" to the end of the URL, the browser will find the element with that ID and scroll directly to that area, a nifty trick for commenting forums or reference pages.
Classes serve a nearly identical purpose as IDs if we are speaking only in CSS terms. They allow you to tag an HTML element and apply specific styling to those elements with that class. The main difference here is multiple classes can be applied to the same element and the same class can be used on multiple elements throughout your HTML document. Classes do not have the special browser functions that IDs have but not to worry, you can apply both a class and an ID to the same element.