In the broad pantheon of eternal wine lingo, perhaps no other phrase carves out sharper lines of drinking identity than the words residual sugar. People tend to define themselves as drinkers by the way they react to its existence, and we can usually track them as tasters this way, too. There seems to be a natural arc moving from the mode of "Yum! That's sweet", to the nose-wrinkling of "Ugh, it's sweet", to "Oh! This wine has a little RS, and that's cool by me..." In the interest of a tolerant spirit, let's explore the whys and the how-comes.
Residual Sugar, or RS for short, refers to any natural grape sugars that are leftover after fermentation ceases (whether on purpose or not). The juice of wine grapes starts out intensely sweet, and fermentation uses up that sugar as the yeasts feast upon it. The by-products are bubbly CO2 gas and our adorable amigo, alcohol.
There are many reasons why fermentation might stop. The age-old method has to do with alcohol toxicity. Different yeast strains can tolerate different levels of alcohol, so a weaker strain might die before eating all the sugar in the fermenting wine. In the case of a dessert wine like Sauternes or ice wine, the sugars are concentrated when the grapes get shriveled, so there's a lot of sugar to ferment. When alcohol reaches the level of a normal dry wine, say 12 or 14%, the yeast might die, but plenty of uneaten sugar is left. In the case of a fortified wine, hard booze is added to get a similar job done.
Fermentation is also temperature-sensitive, happening faster at warm temperatures and slower in the cold, so it will stop if the temperature drops too much. A winemaker can chill a wine down until fermentation stops, then just get rid of the yeast. No more yeast, no more fermentation. Certain chemical compounds can snuff them out, too.
In addition to its obvious sweetening power, sugar also has a bonus effect: it can help wines age well. If you can go the long haul, say, a decade (or two, or three), the RS can bring deep dividends. We've talked >a little about which wines age well: those with a little RS can be the most exciting to taste as they evolve over time. The sugar compounds change shape, and we perceive them less directly, so the wines even seem to dry out a bit.
Whether your bottle is young or elderly, you should think of RS as having a balancing relationship with acidity. They are on opposite sides of the seesaw, so if the wine has sugar you will probably want strong acidity, too—otherwise the wine will feel cloying. On the other hand, certain very high-acid wines, like Vouvray or Riesling, can be far more tasty with a few extra grams of RS. (Remember: we like balance more than anything.)