A loose cassette causes several issues. It tends to rattle around, and makes shifting difficult in both directions.
It’s easy to diagnose a loose cassette – hold the rear wheel in one hand, and the cassette in the other, and slide it along the axle. If it moves even a little bit, it’s loose.
To tighten the cassette, remove the rear wheel from the bike, and unscrew and remove the quick release skewer from the wheel. This gives you access to the cassette lock ring – the part of the cassette closest to the edge of the axle. This lock ring may be a separate component, or may be incorporated into the smallest cog of the cassette.
There’s a proper tool for tightening the cassette lock ring. Most modern cassettes from SRAM and Shimano use one that looks like this. It slips in to the end of the cassette. Then you use a wrench to tighten it, or a wrench and a chain whip to remove it. Of course, on the trail, you probably don’t have this type of tool handy.
If the lock ring is loose, but still functional, place a screwdriver against one of the lock ring splines and tap the handle with the palm of your hand to turn the lock ring clockwise.
If the lock ring is loose, with a stripped thread, try the thread lock suggestions. Otherwise, try “chasing” (cleaning out) the threads using first a knife point or screwdriver, then by carefully screwing another person’s cassette lock ring on to your freehub, and your lock ring on to their freehub.
If the lock ring is tight, but the whole freehub is loose, you will have to tighten up the freehub. Remove the cassette, remove the axle from the hub (typically two thin cone nuts hold this on to the freehub side), catch any bearings that fall out, tighten the freehub back on to the hub body (typically with a 10mm Allen wrench pushed through the non-drive side of the hub) and reassemble. Leave a touch of play in the hub when you tighten down the two cone nuts. This is a pretty advanced move to carry out in the field if you’ve never taken a rear hub apart before – probably better to gently pedal home.
Removing a cassette lock ring
While it’s easy to tighten up a cassette lock ring, removing it can be a pain because the cassette freewheels in the direction that you want to turn the lock ring. In a workshop, you use a chain whip to hold the cassette still while you unscrew the lock ring. On the trail, either jam a screwdriver or Allen wrench between the cassette and the spokes, or wrap your chain nearly all the way around the cassette, holding it in place with a screwdriver or Allen wrench slid through the chain links. In a workshop, you use a cassette removal tool. On the trail, you hold a screwdriver against the splines and bash it.