Why an LED needs a resistor
An LED's current rises very steeply once the voltage across it passes its forward voltage, so connecting one straight across a supply will burn it out in moments. A series resistor drops the extra voltage and sets the current. The value is the supply voltage minus the LED voltage, divided by the current you want: R = (Vs − Vf) ÷ I. For a red LED on 12 V at 20 mA, that's (12 − 2) ÷ 0.02 = 500 Ω, so a 510 Ω resistor from the E24 range.
Strings of LEDs
Putting several LEDs in series, with one resistor, wastes less power because more of the supply voltage goes to the LEDs. Leave at least a volt or two across the resistor, so the current stays steady as the supply voltage changes. In a car or on a battery that varies from 11.5 to 14.4 V, check the current at the highest voltage. For several strings in parallel, give each string its own resistor rather than sharing one, because LEDs aren't perfectly matched.
Power LEDs
High-power LEDs of 1 W and above are usually run from a constant-current driver instead of a resistor, because the resistor would waste a lot of power and the LED's voltage changes as it warms up. For quick sums with resistors in series and parallel, use the Ohm's law calculator, and for reading the colour bands on the resistor, the resistor colour code calculator.
Questions
What resistor do I need for an LED on 12 V?
For a red LED at 20 mA, about 500 Ω, so use 510 Ω or 560 Ω. For a white or blue LED, about 440 Ω, so use 470 Ω.
What resistor for an LED on 5 V?
For a red LED at 20 mA, 150 Ω. For a white or blue LED, about 91 to 100 Ω.
Should I round the resistor up or down?
Up. A slightly bigger resistor gives slightly less current, which is safer for the LED and barely affects the brightness.
What wattage resistor do I need?
At least double the power it dissipates. Most single LEDs on 12 V need a 1/4 W resistor, but check strings at higher currents.