It has to do with the number (ratio) of teeth when comparing the chainring and the cog. To make things easy, let's say that you had a 48 tooth chainring and (implausibly) a 48 tooth rear cog. For every revolution of the crankset/pedals, the rear cog would go around once, too (because there's an equal number of teeth). Make it a 24-tooth cog (while keeping the 48T chainring), and the rear will go around twice for every revolution of the crankset/pedals - you gain speed, but it's at the cost of using more effort. With a 12-tooth cog, the rear wheel would revolve 4 times for every revolution of the crankset, but it would take even more effort. Make sense?