Although much more efficient than they used to be, most water heaters still work they same way they have for generations -- by keeping a giant pot of water piping hot just in case you need some.
Cold water is piped in through a long tube (called the "dip tube") to the bottom of the tank where it is heated by a gas or electric burner much like those on your stove. The warmer water rises naturally and is drawn out of the top of the tank as needed.
Because the tanks are made of steel they are prone to rust and corrosion. A sacrificial "anode rod" is inserted into the tank to attract oxidizing agents to itself instead of to the tank walls.
The size of the water storage tank can range from 20 gallons to 80 or more, but 30-40 gallons is typical for a single family. If this supply is used up too quickly the hot water taps will go cold until more water can be heated.