It is quite easy to calculate the resistor value. The formula is quite simple and you can easily work it out the optimal value for any LED you may find in your junk box.
The formula is :
R = ( Vs - Vled ) / Iled
where
R = Value of current Limiting Resistor to use
Vs = Supply Voltage
Vled = Voltage Drop across the LED
Iled = Current desired
Some notes:
Vs ...
You should know Vs or be able to measure it easily. This is the voltage which is powering the circuit.
Vled ...
You can find the voltage drop across the LED from the datasheet if you have one. In **broken link removed** datasheet for a typical Red LED, the forward voltage is typically 2v
If you don't have a datasheet or have just found the LED in your junkbox you can still find the Forward Voltage of the LED if you have a digital multi-meter with a Diode Test function. Simply select the Diode Test and connect the multi-meter across the LED. The number shown in the display is usually the voltage drop across the LED or silicon junction.
If you don't have a digital multi-meter, you can use the following rules of thumb as a guide
Red = 1.8v
Orange = 2.0v
Yellow = 2.1v
Green = 2.2v
Iled ...
Once again, the dathesheet will tell you the maximum current. In the datasheet above this is 15ma. As a rule of thumb, you can allow up to 20ma of current to flow through most LEDs and in abscence of data telling you otherwise, this is the value I would choose.
While the current flowing through the LED is one thing to consider here, you also need to consider other parts of the circuit, in particular your current source and sink. In other words, where is the current coming from and where is it going to. If you are driving the LED from a micro, many can sink more current than they can source. You will need to check this by refering to the datasheet for the micro.
R ...
Once you have calculated the optimal value for the resistor, you would then select the next closest value available, chosing a resistor which was a little higher than that calculated. For example, using the LED above, we would calculate..
R = 5v - 2v / 0.015a
R = 200
While 200 ohms is a prefered value within the 1% metal film range, we would probably use a 220 ohm resistor which is the closest prefered value in a standard 10% carbon series.
I am certain that if you Google around for a while, you will find many web sites which will explain this to you with pretty pictures and everything.