There are two major standards (ways) of attaching bicycle cassettes to the rear wheel: old freewheel and the newer freehub. The differences and how to tell one from the other are explained in this post.
Rear hubs are explained in the Bicycle rear hub post, while here the emphasis is on sprocket sets (i.e. cassettes) themselves. Sprocket sets come in two standards: freewheel, or a freehub (with a cassette). Depending on the type of rear hub, one or the other type is used. An image speaks clearer than a thousand words:
Attention should be paid to this when buying and changing sprockets, so that the right ones are used. Freewheel is screwed onto the rear hub, while cassette is just slid onto the hub splines, held in place with a special lockring. The very end of the (rear) hub differs for each type, so it is easy to identify the standard, even before removing sprockets:
Apart from this, it helps with identification knowing that Suntour freewheels usally come with 5, rarely 6 sprockets, Shimano and SRAM freewheels are usually with 6 or 7 sprockets (extremely rarely 8, or 9, but that is dangerous for the rear axle, as it is explained in Bicycle rear hubs post).
Cassettes usually come with 7 (seven is the most rare), 8, 9, 10, 11 sprockets. Superior standard than freewheel.
That is why when buying new (to replace worn) sprockets, it is important to know whether it is a freewheel or cassette. If buying a new (rear) hub, it is better to buy a freehub one, for cassettes, but if changing just sprockets, in case the hub is for freewheel, it is very expensive to buy the wrong, cassette type sprockets, since they require the change of hub as well, which is more expensive.
Frewheels come with sprockets bolted together, without possibility of swapping them. Cassettes come with loose sprockets that have spacing between them. Some cassettes do come with sprockets held together with bolts or rivets, but these are just for easier mounting – they can be removed without affecting functionality, so that individual sprockets can be swapped.
Images explain better:
There is an old “Uniglide” standard for freehub splines, and a new “Hyperglide”.
Old Uniglide was completely symmetric, so allowed sprockets to be placed in whatever position. Hyperglide has one wider spline, and sprockets have one wider groove for that wide spline, so they can only be placed one way. This way sprockets are placed so their teeth rotate exactly the same way, which allows for better shifting, allowing the chain to engage two adjacent sprockets at the same time, practically climbing onto the next gear (sprocket).
Big advantage of Uniglide is that it allows for sprockets to be flipped on the other side, which practically gives a new cassette (unworn side is used)!
When shopping for a new rear hub, it is wise to get a freehub type, and make it a Hyperglide freehub, avoiding the old standards. Hyperglide freehub will accept Uniglide sprockets as well (except the smallest, locking sprocket – Hyperglide uses a special nut for locking the cassette in place).
Update as of summer 2018:
Both Shimano and SRAM have made one new freehub standard each (with matching cassettes), for their 11 and 12 speed MTB cassettes. SRAM’s standard is called “XD“, while Shimano’s is called “Hyperglide+“.