During primary fermentation, the yeast you add to your wort consumes the sugars present and converts them into alcohol. This is a wonderful thing. However, there are some potential problems with prolonged primary fermentation. After the initial, vigorous phase of fermentation has subsided, particles that are suspended in your beer will gradually settle to the bottom of the carboy. These particles can include undissolved sugars, spent grain husks, fragments of hops and remnants of any adjuncts you've added to your beer. However, the lion's share of this layer of sediment that forms on the bottom of your carboy will be made up of dead yeast cells.
During the initial yeast bloom that occurs during vigorous fermentation, the yeast cells have copious amounts of food (sugars) and a friendly environment, and as a result they will breed rapidly. As fermentation continues, the declining quantity of sugars present in the beer will not be enough to support this large population of yeast, and most (though not all) of the yeast cells will die. Yeast cells are living organisms, and like any living organisms, after they die they begin to break down and decay. These decaying cells will, over time, release undesirable byproducts into your beer which can have a very significant (and usually negative) impact on your beer's flavor. For this reason, it is important not to prolong the process of primary fermentation. Once you have established that fermentation is complete, you should remove your beer from this environment as soon as possible.
However, you may not be ready to bottle your beer at this time, for one of any number of reasons. Many of the more complex styles of beer need additional time to develop their character. You may want an end product that is cleaner, clearer and crisper, without the haze or cloudiness that many homebrewed beers have. You may not have the proper materials on hand to bottle, you may not have the time, or you may flat-out not feel like it. This is where secondary fermentation comes in.
Secondary fermentation is the process of transferring, or "racking", your beer from one carboy to another, leaving the dead yeast and other sediment behind, to allow it to continue aging and fermenting. Secondary fermentation is different from primary in a number of ways. While there may be a minor upsurge in yeast activity immediately after racking the beer, this will only be temporary and is due more to the agitation of the beer in transit than anything else. There will be no vigorous activity as there was during primary fermentation, since most of the soluble sugars have already been consumed.
Also, secondary fermentation is an open-ended process. That is, there is no finite end to it - it's over when you say it's over, although it's a good idea to let it go on for a minimum of two weeks. This increased element of flexibility, when combined with the other advantages of secondary fermentation, makes the process desirable for lazy homebrewers like myself. It is not, however, for the impatient homebrewer, as it means another two to six weeks or more before you can drink your beer.
In order to perform this step, you will obviously need another carboy. I suppose it would be possible to rack your beer to a holding container while you cleaned and sanitized your primary carboy, and then rack it back into that carboy, but you'd be significantly increasing the risk of contaminating your beer. Buy another carboy, they're only about $15 US. The procedure for racking to secondary is essentially the same as racking to your bottling bucket. Set your second carboy on the floor, or somehere a couple feet below your first carboy, and use your thin flexible plastic tube to siphon the beer from the first carboy to the second. A little of the sediment in your first carboy will inevitably be sucked into the second one, but try to keep it to a minimum. Once racking is complete, put a stopper and fermentation lock on your second carboy and place it up off the floor where the original one was. Make sure you cover it, and then you're done.
This is also an ideal time for dry-hopping. Dry-hopping is a practice used most commonly in IPAs and ESBs, but which can be used in other hoppy styles of beer as well. Adding hops to the carboy at this point will result in them lending their characteristic flavor and aroma to the finished beer, without adding any bitterness. For details on the chemistry of hops and their components, as well as a list of which major varieties of hops are best to use for these purposes, consult Homebrewing 202: Hop Selection and Use.
Some brewers will use a "hop bag" for this purpose - a fine mesh bag into which the hops are placed, which in turn goes into the carboy. This is essential if you are using whole hops, and optional if you're using pellet hops. It's also a good idea to put a sterilized sinker, bolt or other weight in the bag, or it will float. It is important to agitate your beer at least once a day for the first week or two after you add the hops. This will help distribute their flavor throughout the beer. If you're using pellet hops without a bag, agitating will also help saturate the hop particles with beer, which will result in their eventually sinking to the bottom of the carboy. Otherwise, they will float in a layer on the top.
The agitation of your beer will obviously prevent sedimentation, and will thus lengthen the time it must spend in secondary fermentation. In addition, if you're not using a hop bag, you will need to strain your beer through a fine mesh strainer on its way into your bottling bucket in order to filter out any stray particles. I personally use pellet hops without a bag, and it works just fine.
Lager-style beers will require a secondary fermentation, and for these beers it can be a lengthy process, lasting several months. This will be discussed in a later node on lagering, since there are several other aspects involved which warrant their own section.
Secondary fermentation is also an essential step in brewing beers with fruit in them, such as a raspberry weiss. The amount of fruit you'll use will vary depending on the style of beer and how subtle or strong you want the fruit flavor to be. Run the fresh fruit through a foley mill or other juicing device and add the resulting juice to your beer during secondary fermentation. Note that this will cause a resurgence in fermentation activities as some of the fruit sugars are processed by the yeast. However, because these sugars are chemically more complex and have not been boiled, they will be more difficult for the yeast to break down. This will result in a lengthier fermentation and a sweeter beer.
When brewing fruit beers, it is also common practice to allow them to undergo a tertiary stage of fermentation. This is because the resurgent fermentation of the fruit sugars will cause another bloom of yeast cells (although nowhere near as large as primary fermentation), and another layer of dead yeast at the bottom of the carboy. The particles of fruit pulp that inevitably make their way into the carboy will also need time to settle out. For this reason, it's best to rack to another carboy after secondary fermentation is complete, and give the beer a few more weeks to settle and age. The procedure for tertiary fermentation is identical to that of secondary fermentation, so I will not be creating a separate node for it.
In conclusion, while a second stage of fermentation lengthens the brewing process and complicates it slightly, it also has a dramatic effect on the flavor, clarity and quality of your finished beer, and gives you more freedom and flexibility in scheduling when you bottle your beer. You can allow secondary fermentation to continue indefinitely - I recently bottled a batch of ESB which I had basically forgotten about. It had been in secondary for over six months, and it turned out in my opinion to be one of the best beers I've ever made: clean, clear, crisp and hoppy. Once you start employing secondary fermentation, it's likely that you'll never look back.