The wiring in a typical residence can get complicated, and in an effort to keep track of what's what, electricians -- partly by convention -- assign certain colors to the wires in an electrical circuit. The National Electrical Code mandates particular colors for the ground wire and the neutral or return leg of a grounded circuit, but it doesn't say anything about the hot wires. This is ostensibly to prevent electricians from an over-reliance on color.
Ground Wire Colors
The grounding wire in your switch or outlet box isn't actually a part of the circuit -- but in terms of safety, it's the most important one, because it diverts anomalous current to earth and prevents fires and electrocution. The NEC requires the system grounding conductor to be covered with insulation that is green or green with yellow stripes, or it can be bare. In practice, the ground wire in most 120- and 240-volt circuits is bare, but if you run across a green wire, it's a ground wire. The NEC prohibits using ground wire colors for other conductors.
Neutral Wire Colors
The Institute of Electrical and Electronics Engineers defines the neutral wire in a circuit as the one with an equal potential between itself and all the other conductors. It's usually bonded to the case of the power supply and is more properly called the grounded conductor -- as opposed to the equipment grounding wire. A grounded conductor -- or neutral wire -- smaller than 4 AWG must be identified by a white or gray covering, or one with white stripes. Neutral wires larger than 4 AWG must be gray. In everyday residential wiring, the neutral wire is almost always white.
Hot Conductor Colors
Because the NEC doesn't specify a color for the hot conductor in a circuit, any color can be used except for those that identify the grounding or neutral wires. In practice, hot wires are either black or red in a 120- or 240-volt residential electric circuit. Black is the default color, and the wires in a 2-conductor cable with a ground wire are white and black. The two hot wires in 240-volt circuits -- which must be wired with 3-conductor cable -- are red and black. The voltage across either hot wire with respect to the neutral wire is the same -- 120 volts.
You may see a red wire in a 120-volt circuit, and when you do, it usually has a particular significance. Two light switches that power the same fixture must be connected by a hot wire, and this wire is usually red. A 3-conductor cable may also be employed to connect a double switch to a ceiling fan that has a light fixture. The red wire may power the fan and the black wire the light switch, or, because no regulation prevents it, the opposite may be the case. The hot wires in certain fixtures may not be red or black -- they could be yellow, pink or even blue. You may need to consult a circuit diagram to decipher the wiring in such fixtures.