The short answer
Sweetness in wine is measured as residual sugar in grams per litre: under about 4 g/L reads as dry, 4-12 g/L as off-dry, 12-45 g/L as medium, and anything above that as sweet. Dessert wines run from 45 g/L to over 200.
What complicates it is acidity. A high-acid wine tastes drier than its sugar level suggests, which is why a German Riesling at 30 g/L can read as crisp while a soft red at 10 g/L reads as sweet. Perceived sweetness is the balance, not the number.
Why acidity changes what you taste
Sugar and acid pull against each other. Raise the acid and the same sugar level reads as fresher and less sweet; drop the acid and a modest sugar level tastes cloying. This is the entire reason Mosel Riesling works: 40 g/L of sugar against very high acidity tastes lively rather than sticky.
It also explains a common confusion. Wines described as tasting sweet are often bone dry: ripe fruit character and oak-derived vanilla read as sweetness to the brain without a gram of sugar being present. A big Californian Cabernet is a regular victim of this.
How to tell before you buy
Alcohol is the best clue on a bottle that does not state sweetness. Fermentation converts sugar to alcohol, so a low-alcohol wine has often had that conversion stopped early, so an 8% Riesling is almost certainly off-dry or sweeter, while a 13.5% one is likely dry.
Then the labelling terms, remembering the sparkling inversion above. Then the region: Vouvray, Mosel and Alsace all make dry and sweet versions of the same grape and rely on you reading the label.