Find the series resistor for an LED from the supply voltage, the LED's forward voltage and current. Includes the nearest standard value and power rating.
The resistor drops the difference between the supply and the LED forward voltage at the chosen current: R = (Vsupply − Vforward) / I. Use a resistor rated above the power shown. Typical LED forward voltages: red ~1.8V, yellow/green ~2.1V, blue/white ~3.2V.
The resistor carries the LED current and drops the leftover voltage: R = (supply voltage − LED forward voltage) ÷ current. For a 12V supply, a 2V LED and 20mA, that is (12 − 2) ÷ 0.02 = 500 ohms.
Use the values from the LED datasheet. As a rough guide, forward voltage is about 1.8V for red, 2.1V for yellow and green, and 3.2V for blue and white; 20mA is a common, safe current for standard 5mm LEDs.
The resistor turns the dropped voltage into heat. If that power exceeds the resistor's rating it will overheat. Pick a resistor rated comfortably above the figure shown, for example a quarter-watt part for anything under about 0.1W.