The human tongue responds to a range of different substances, registering them as various tastes. Evolution programmed our gustatory sense to find nutritious things tasty, and un-nutritious things un-tasty — for the most part. Human beings are flexible about what they eat relative to many animals, hence our omnivore status, but there are many types of organic material that we are incapable of digesting, and hence perceive as unpleasant. Sugar is highly digestible and offers a very condensed source of calories, so to us it tastes good — and has a distinct flavor that we label sweet. All mammals, except cats, can taste and enjoy this substance and are more inclined to eat poor-tasting food if it contains some.
Scientists now know that the tongue is covered with tiny clusters of chemical sensors called taste buds. It is the geometric shape of incoming molecules that determines how they taste. Some foods have multiple molecules that all contribute to their overall taste sensation. There are several types of sugar that exist, but by far the most frequently consumed by humans is a molecule called sucrose. There are also other molecules, like saccharine, that taste sweet even though they aren't sugar, although the taste sensation is slightly different.
The reason that two different classes of molecule produce the same sweet taste was confirmed in the 1960s. They both have a dual set of hydrogen atoms poking out from their surface like a prong, ready to bond with receptors in the tongue. In sugar, these two atoms are between 2.5 and 4 angstroms apart, where an angstrom is a length approximately equal to the width of two hydrogen atoms. Saccharine has an entirely different molecular structure, but the same prongs with similar spacing, leading to a similar taste sensation.
Bitter-tasting substances also have two hydrogen atoms sticking out for bonding, another prong, but the average separation of these two atoms is 1.5 angstroms. The different spacing of hydrogen atoms by a mere few atomic diameters is enough to produce the high level effect of either sweetness or bitterness. That is why sugar tastes sweet, and quinine tastes bitter.