Most people like to take a break from pedaling once in a while during their bike ride and just coast along, either to cruise down a hill or catch their breath for a few moments on a smooth, flat stretch of road. Many people don't understand the inner workings of the mechanism that allows you to coast. What keeps your feet from having to keep moving with the wheels? The answer is either a freewheel or a freehub.
All modern multi-speed bikes use either a freewheel or a freehub system on the rear wheel, unless they are using an internally geared rear hub. Most bikes with 7 gears or less on the rear wheel use a freewheel; most bike with 8 gears or more on the rear wheel use a freehub, although there are some 7-speed freehub systems in use. The outward appearance of a freewheel and a freehub is not noticeably different to the average bicycle owner.
In both cases, inside the freewheel or freehub is a set of bearings that are separate from the bearings inside the wheel's main axle. Working in conjunction with these bearings is a set of spring-loaded pawls. When you pedal forward, the pawls lock into position to turn the wheel forward. When you stop pedaling, the pawls release, causing the clicking sound that you usually hear when coasting.
The difference between a freewheel system and a freehub system is in the location of the coasting mechanism.
On a freewheel system, the coasting mechanism is built into the gear cluster. The term "freewheel" refers to the whole gear cluster with the coasting mechanism inside. The freewheel is screwed onto a set of threads on the right-hand side of the wheel's hub.
On a freehub system, the coasting mechanism is a sub-assembly of the wheel's hub. The gear cluster is a unit with non-moving parts, and is referred to as a cassette. The cassette slides into place onto the freehub body and is held in position by a series of ridges, or splines, and locked in place using a cassette lockring.
The diagram below highlights the differences between freehub system (top) and a freewheel system (bottom).
The red dots indicate the position of the main hub's axle bearings. Notice how they are more widely spaced on the freehub axle compared to the freewheel axle. The freewheel bearing placement worked great for decades and was durable enough for most applications. However, when mountain biking exploded in the 1980's, riders experienced frequent problems with their axles snapping in half. This led to the development of the more durable freehub system, and it's used on most better bikes (road as well as mountain) priced over $400. You are still likely to find the less-expensive freewheel system on bikes under $400.
When the mechanism wears out in a freewheel, you just replace the entire freewheel (with gear cluster). When the freehub mechanism wears out, you can remove the cassette, replace the freehub, then re-install the cassette.
These days, since freewheels are mostly used on kid's bikes and less-expensive adult bikes, the quality level of most replacement freewheels available are pretty much equivalent. However, there are a wide range of freehubs available from a variety of manufacturers today. One of the things that makes one freehub better than another is the number of pawls in the freehub mechanism, and the number of engagement points for the pawls. Increasing the number of pawls and/or engagement points makes the freehub engage faster when you start pedaling, with less free "spinning" before the force of your legs gets put to use.
For single-speed drive trains, both the freewheel and and freehub mechanisms are in common use. The working principle for both is the same as their multi-speed brethren. A single-speed freewheel has the coasting mechanism built inside a single cog that is bolted onto the wheel's main hub. These are common on BMX bikes, most single-speed kid's bikes, and many single-speed mountain bikes (both high- and low-end).
A single-speed freehub has the same type of splines as a multi-speed freehub; the freehub body is just shorter to accomodate a single cassette cog. The are common on many single-speed mountain bikes (both high- and low-end).