Up until quite recently wheel rims have taken quite a beating from constant wear caused by a combination of brake blocks, grit and road grime. Over time the constant friction wears away at the aluminium or carbon. There may come a time when your current front wheel, rear wheel or wheelset shows significant signs of wear on the rim. The hubs may still be working perfectly well and, to be honest, why wouldn’t they, you’ve taken great care of the bearings, pawls etc and they run today as good as they always have.
Or maybe, a mishap or accident has seen your wheel take a nasty bang or crack from a pothole or a crash and the only damage is to the rim. Many wheel manufacturers stock rims as service parts and in the hands of a good wheel builder the hub may still have plenty of cycling days to come. You may need to replace some or all of the spokes but if the hub is of a high quality, it may still be beneficial to rebuild the wheel rather than buying a new wheel or pair of wheels.
Wheel rims come in many sizes for road or off road use. 700c, 29er or 650b being the most common with 26in becoming less so. With the development of disk brakes both for MTB and more recently road bikes, bike rims may not have (or need) a braking surface, so care must be taken when replacing your current rim if you intend to run rim brakes (caliper, cantilever or V-brake) to ensure compatibility.
For road bikes, the development of carbon fibre rims has seen a great range of rim depths, with deeper rims being more suited for aerodynamics.
Whether you are replacing a road bike rim or a mountain bike rim, consideration must be given to the hole count to ensure the rim matches the hub. As a rule try and obtain the rim with its direct replacement and be careful to take note of the year of manufacture, as some wheel manufacturers may have updated or changed the rim from one particular year and it may not be compatible or match the one you have on the front or rear.
As disc brakes become more and more common, so wheel rims will start to become lighter with no need to build in a braking surface, but for now both carbon and aluminium rims are still readily available for wheel builds and re-builds.