Every light-emitting diode (LED) has a current that they can safely handle. Going beyond that maximum current, even briefly, will damage the LED. Thus, limiting the current through the LED with the use of a series resistor is a common and simple practice. Note that this method is not recommended for high current LEDs, which need a more reliable switching current regulator.
Calculate Resistor value for LED series
To calculate the resistor needed for a simple LED circuit, simply take the voltage drop away from the source voltage then apply Ohm's Law. In other words.
LED Series Resistor Calculator Formula =
R = (Vs - Vf) ÷ If
Where:
Vs= Supply voltage
If= LED current. The usual operating range of common 3 mm and 5 mm LEDs is 10-30 milliamps. If access to an LED's datasheet is impossible, 20 mA is a good guess.
Vf= LED voltage drop. The voltage drop on a LED depends on the color it emits. Here is a neat table of each color and their corresponding voltage drop: