How to Calculate the Resistor for an LED: Formula, Worked Examples and a Cheat Sheet
To calculate the resistor for an LED, subtract the LED's forward voltage from the supply voltage and divide by the current you want: R = (Vs − Vf) ÷ I. For a red LED (about 2 V) on a 5 V supply at 20 mA, that's (5 − 2) ÷ 0.02 = 150 Ω.