To calculate the value of the series resistor we need to know the diode forward voltage and current and its connections. The necessary data can be obtained from a catalogue or data book. In our example it is 2 volts and 20mA (0.02 amps). The cathode lead is the one nearest a "flat" on the body.
Since the voltage across the diode is 2 volts and the battery voltage is 12 volts, then the voltage across the resistor is 12-2 = 10 volts. The diode is in series with the resistor, so the current through then both is the same, 0.02 amps.
We now know the voltage across, and the current through the resistor. From Ohm's Law we can now calculate the value of the resistor.
Resistance = Volts divided by Amps = V/I = 10/0.02 =500 ohms.
Since this is not a standard value we can use a 470 or 560 ohm resistor as this application is not critical of values.