The difference between 5w-20 and 5w-30 oil is that 5w-30 oil has a higher viscosity at its operating temperature. Viscosity is the term used to describe the thickness of a substance, in this case oil, where a higher number indicates a thicker oil.
Oil viscosity varies inversely with temperature. This means that as the temperature goes up, the thickness (viscosity) of the oil decreases. To use this knowledge in an automotive application, it is important for an oil to be thin enough to spread quickly when a cold engine is started, yet it should not become too thin once the engine reaches its operating temperature. An oil with the rating of 5w-30 is a multiweight oil that will act like a 5-weight oil, which is very thin at cold temperatures, while maintaining the thickness of a 30-weight oil once the engine reaches its operating temperature. This protects the engine from wear at both temperature extremes.
The invention of the modern multiweight oil is made possible by the addition of polymers, which coil up at cold temperatures and mimic shorter molecular chains with a lower viscosity. As the oil's temperature rises, these polymer chains begin to unwind, increasing the effective length of the molecular chain and thereby increasing the viscosity.