Bike Wheel Components--Spokes, Nipples, Rims, and Hubs
Spokes
Spokes are made from rolls of wire. The wire is straightened and cut to the right length, one end is threaded, and the other end is pressed into a nail-type head and an elbow is bent. DT Swiss and Wheelsmith are the major manufacturers of quality spokes. Good spokes are stainless steel (exotic spokes can be carbon fiber or titanium). Galvanized spokes are junk--they will rust and corrode.
The most common diameters of spokes are 1.8 mm (15 gauge) and 2.0 mm (14 gauge). Some spokes are butted--the ends are thicker than the middle. Thinner and butted spokes are more aerodynamic and slightly lighter but are not as strong. Road bikes often have bladed spokes, which are more aerodynamic. When replacing a spoke, use the same gauge spoke to keep the same spoke-flex properties throughout your wheel.
Spokes come in many lengths. Most mountain bike wheels use spokes around 260 mm, and most road bike wheels use spokes around 300 mm. When buying spokes it is important to be precise. You don't want the spoke sticking up into your tube, and if a spoke is too short it will break pronto.
Spokes on non-disc front wheels are the same length on both sides. On rear wheels, the drive side spokes are usually shorter than the left side spokes. On disc brake wheels, spokes on the brake side are sometimes shorter than on the non-brake side.
It is best to measure spokes off the wheel with a Park spoke length measuring tool.
Fudge on the long side. Too short a spoke will break. A double wall rim will keep a too long spoke away from your tube, and you can file down a long spoke end and cover it up with thick rim tape.
If you are building a new wheel with new components, ask your vendor to calculate the spoke length for you. You can find the correct length yourself on this on a number of websites--search for "bicycle spoke length calculator."
The information needed to calculate spoke length is:
effective rim diameter--ERD--see Rims below
number of spokes
crossing pattern, e.g. 3 cross, 2 cross, etc.
hub details
the distance from the center of the hub (center between the outside of the locknuts) of each flange--the distance is smaller to the rear hub drive side flange and longer to the non-drive side flange
the distance from center to center of the flange spoke holes directly opposite from each other (most commonly 45 mm on non-disc rear hubs)
Measuring the hub details is not so hard. Measure the distance between the outside of the locknuts--usually 135 mm on mountain and hybrid bike rears, 130 mm on road bike rears, and 100 mm on fronts. Draw a line that long on a piece of paper, and place the hub on that line with the locknuts directly over the ends of the line. Mark where the flanges are--the flange point. Mark the center-point on the line (1/2 135 mm, etc). Measure the distance in millimeters between the center-point and each flange point, and wha-la! you have the center-to-flange distances. Then take a measuring caliper and find the distance between the center of the flange spoke holes directly opposite each other.
Now you are ready to plug these numbers in any spoke length calculator easily found on the internet.
Nipples
Nipples must be the same interior size as the spoke. Be careful--a 2.0 mm nipple will thread on a 1.8 mm spoke and the threads will promptly strip.
You would think that all same interior-size nipples (1.8 or 2.0 mm) would have the same size wrench surface, so the same size spoke tool would work on all 1.8 mm nipples or all 2.0 mm nipples---but NOOOO! Modest priced wheels made in the Far East require a bigger spoke wrench than upper end wheels. So use the Park red spoke wrench on Far East spokes, and the Park black spoke wrench on nicer wheels. What's even screwier is that you can't buy nipples that fit a red spoke wrench--they all fit a black spoke wrench. So if you have to replace a nipple on your modest wheel, you will need different size spoke wrenches to work on your wheel.
Some wheel manufacturers think it is cute to use exotic nipples that require a spoke wrench only they manufacture. If you are stuck with one of those wheels, you better take your wrench everywhere you ride.
Nipples can be brass or aluminum. Aluminum nipples are nano grams lighter and a lot more fragile. Stick with brass.
Rims
Rims are made by exuding hot aluminum through a die producing a straight piece of metal, which is cut, bent around a mandrel, and pinned and/or welded together. High quality rim-brake rims are machined on the side to perfect the braking surface.
Steel rims are junk--don't buy them.
Good rims are double walled.

Some road rims are shaped in a deep V, which adds strength and stiffness. Deep Vs are necessary for a rim with few spokes. So save some weight on spokes, add some to the rim, net weight result about the same.
Many rims have spoke eyelets--metal reinforcement rings around the spoke holes. Eyelets make for a stronger wheel.
A replacement rim has to be the right diameter. Most mountain bikes use 26 inch rims. Most modern road bikes use 700C rims, which are about 27 inches in diameter. Note though that rims designated as 27 inches are a different size than 700C rims and they are definitely not interchangeable.
Rims described as 26 X 1.25 are not the same diameter as 26 X 1 1/4 rims.
The second part of the rim description--26 X 1.25 or 700 X 1--reflect the width of the rim and are not as important in buying a replacement rim. Tires will fit on slightly varying rim width, but not on the wrong rim diameter.
To calculate the right spoke length, you need to know your rim's effective rim diameter--ERD. ERD is the distance from the butt end of a spoke nipple inserted in spoke holes directly opposite of each other, stated in millimeters. Notice that this is not the rim diameter, and it is not the distance between the outside of opposite spoke holes. It is the distance between opposite spoke holes plus the thickness of the rim wall plus the thickness of the butt of the nipple. Some rims have the ERD stated on the label. Your vendor should be able to tell you the ERD. Wheelsmith sells a spoke length calculation system, including an ERD measuring system, if you want to do it yourself.
Spoke holes are drilled in the rim, alternating one closer to the left side and one closer to the right. The spoke in the left hole goes to the left hub flange, and vice versa.
Some rims for rear wheels are offset. That is, the spoke holes are not centered on the rim, but are offset a little to the drive side. This reduces the wheel dish slightly. Don't use an offset rim on your front wheel unless it is specifically designed for a front disc brake wheel.
Good quality double wall rims are available for $40 or less. Very expensive rims may be lighter or more precisely machined, but are unlikely to be any stronger.
Hubs
Quality hub bodies are mass produced with a cold forging process. A block of aluminum is placed between 2 dies, and the dies are pounded together repeatedly. Some exotic, expensive hubs are CNC machined, but forging results in a stronger hub. It's hard to beat a mass produced Campagnolo or Shimano hub.
For the internal workings of hubs click on the hub section.
Of course, the number of spoke holes in the hub must be the same as in the rim.
Almost all front hubs are 100 mm between the exterior surfaces of the locknuts.
Most road hubs are 130 mm between the exterior surfaces of the locknuts.
Most mountain bike hubs are 135 mm between the exterior surfaces of the locknuts. Some old hubs are 126 mm.
So, you can't fit a road bike hub on a mountain bike, or vice versa, without bending the frame.
When buying an internally geared rear hub, pay attention to the hub width and dropout width on your bike.
If you want to build a radially laced (0 cross) wheel, shop around for your hub. Most hubs are not warranted against failure if radially laced. That said, I've built some radially laced wheels on non-warranted hubs and they haven't failed yet.