Decanting serves three purposes and applies primarily to red wines of reasonable quality or age.
First: it allows the wines to 'breathe'. Contrary to popular belief, pulling the cork and allowing your wine to stand for an hour in the bottle has virtually no improving effect even though you see this done in restaurants all the time. The tiny amount of air in the neck of the bottle is simply too small, relative to the amount of wine, to have any effect - unless you left it open for nearly a day. To effectively aerate a wine, you must pour it into a decanter, carafe or pitcher so that it mixes with oxygen. When allowed to breathe this way, many wines - especially young, tannic reds (such as cabernet sauvignon, merlot, nebbiolo and shiraz) will open up and the flavours soften. White wines will also open up as a result of exposure to oxygen, though the effect is less pronounced. Delicate reds need special attention so the flavour is not blunted. Do not splash a pinot noir into the decanter, and older Burgundies, Riojas and Chiantis are rarely poured out to aerate them.
Second: it separates the clear wine from sediments that have formed naturally during maturation. You could drink the wine that has thrown some sediment without decanting it - the sediment is not harmful, just slightly gritty. In order to decant, the wine bottle must be upright for a day or two to allow all the sediment to settle to the bottom. Without moving or lifting the bottle, remove the cork slowly. Pick up the bottle gently, with a light source behind it and pour the wine slowly into your decanter. When an inch or two is left you should see the sediment coming into the neck of the bottle - stop decanting. Old wines are often unpredictable and frail and in the presence of oxygen may begin to die. The rule of thumb is to decant older tannic wines - port, cabernet sauvignon, Bordeaux, Barolo and Rhone wines, for example - less than an hour before serving. More fragile wines that were never strongly tannic or deeply coloured in the beginning may never need decanting, but do so just before serving if you see sediment.
Thirdly: since wine is an experience of the senses, your decanter gives you added visual pleasure. Many of the most beautiful decanters have been made from lead crystal since 1674 since it was discovered that adding lead oxide to molten glass made it softer and easier to cut into elaborate designs. Moreover, it made the glass more durable and brilliant.