It uses a zener diode inside. A zener diode acts like a normal diode (letting voltage flow only one way).
Put it in backwards, though, and the voltage has to exceed the "zener voltage" of the diode (giving
it its name), at which point the diode begins conducting. This, with a low-value (say 680 ohm) resistor to
limit the current through the diode (you don't want to shunt your entire source power supply to ground!),
connected power->resistor->diode->ground, gives you a nice, stable (but very-low power, on the order of
.25 watt or less) voltage regulator. If you want to up the power to a useful level, you connect the diode from
the base of an NPN transistor to ground, and a low-value resistor from collector to base. Pump in as much
voltage as you'd like (within the specs of the transistor, anyway) and it'll give you a constant-voltage output
on the emitter, at the zener voltage of the zener diode. Congratulations, you've just built a linear
regulator - the most basic form of power supply. A 7805 (or 7812, or any number of similar chips) just gloms
it all into one package.
As an aside, if you need a hefty power supply, try this:
12v 30A power supply
You can replace the 7812 regulator with anything you'd like (including the schematic I described above, and
any value of zener), and get as much or as little voltage as you want. I recently built a very hefty 48v power
supply out of that - I just left off the input transformer, and bought capacitors and transistors rated to 200VDC
(if line voltage scares you, don't try that at home!). I haven't tested its amperage capacity yet, but I estimate it
at around 20A (I used transistors with somewhat different ratings).