A light emitting diode is a diode first and a lamp second. Like any diode it conducts in one direction only, and once the voltage across it passes its forward voltage it conducts hard, with current rising steeply for tiny extra voltage. The light comes from electrons falling across a semiconductor junction and giving up energy as photons; the material sets the colour, from the deep red of older indicator lamps to the gallium nitride blues and whites that light modern rooms. Efficiency has climbed for decades, which is why LEDs displaced filament lamps almost everywhere.
Because current rises so steeply past the forward voltage, connecting an LED straight across a supply invites disaster: a slightly high supply, a warm junction or a part from the fast end of the production spread can push the current far beyond its rating and destroy the device in seconds. The series resistor absorbs the leftover voltage and sets the current almost regardless of the LED's exact behaviour. That is also why the resistor calculation subtracts the forward voltage first: the resistor only ever sees what the LED does not take. With 5 volts, a 2 volt red LED and 20 milliamps wanted, the resistor drops 3 volts and must be 150 ohms.
Forward voltage depends on colour and chemistry: roughly 1.8 to 2.2 volts for red, orange and yellow, around 3 to 3.4 volts for blue, green and white. Datasheets give a typical figure and a range, and designing with the lowest expected value gives the highest, safest current estimate. Brightness follows current closely at first, then flattens while heat keeps rising, so doubling current never doubles light for long. Modern indicator LEDs are bright at 2 to 5 milliamps, kinder to batteries and resistors alike. The calculator on this site works the resistor out and picks the nearest standard value, showing the current that value actually delivers. A word about running LEDs from AC and from each other. On alternating current an LED conducts on one half-cycle only and needs reverse-voltage protection, since most LEDs tolerate only about 5 volts in reverse; a second diode or an antiparallel LED is the standard guard. LEDs in series share one resistor and one current, which suits matched parts from the same batch, while LEDs in parallel each deserve their own resistor, because the one with the lowest forward voltage will otherwise hog current, run hot, drop its voltage further and hog more, a small thermal runaway that ends with the brightest LED dying first. Manufacturers bin LEDs by voltage and brightness precisely to keep these behaviours tame.
The free calculator that goes with this guide:
Open the LED resistor calculator