Most LEDs will burn out if connected to a 9V battery without a resistor. The resistor lowers the amount of current flowing through the LED.
Read more here: http://www.robotroom.com/Pumpkin3.html (NOTE: in the breadboard photos there is power -red- on one side and ground -black- on the other, not next to each other like other, more expensive, breadboards.)
LED legs are different lengths to help you quickly remember which side to connect to power. The long leg of the LED connects to power, and the short leg connects to ground. However you can cut the legs however you want, in which case you will have to remember or mark that LED (there is also a flat spot on the lens but it can be difficult to see). Hooking it up backwards will not hurt anything.
To calculate how much resistance is needed, you can assume the average LED takes around 2V and 20mA (if you want to be more precise, look up by color using http://ledcalculator.net/). For these simple experiments, resistor values do not need to be exact (+-20% is fine), but if you calculate exactly you get the most brightness without losing efficiency, and also the best battery life.
Ohm's Law: R = V / I
For an LED circuit, you must calculate the resistance needed to limit current to the LED so it doesn’t burn out. You will calculate using the voltage across the resistor, i.e. subtracting the voltage drop from the LED.
R = (V_source - V_LED) / I
For example, with a 9V battery and an LED with a voltage drop of 2V, if you want 20mA (0.02A) of current to flow through it:
R = (9 - 2) / 0.02 R = 7 / 0.02 R = 350 ohms
But you don’t need to worry about the math! Just use an LED calculator/wizard like the ones linked in the reading.
If you wire more LEDs in series, or you use white or blue LEDs which require more power, you will need a lower resistor. Depending on your voltage source, there will be a limit to how many LEDs will work in series. You can also wire LEDs in parallel, where each one has their own resistor. Lastly, you can combine parallel strings of LEDs in series.