(CNN) -- When you're thirsty and in need of a drink, which beverages are best at keeping you hydrated?

Sure, you can always reach for a glass of water -- but plain H2O isn't the most hydrating beverage around, according to a study from Scotland's St. Andrews University that compared the hydration responses of several different drinks.

The researchers found that while water -- both still and sparkling --does a pretty good job of quickly hydrating the body, beverages with a little bit of sugar, fat or protein do an even better job of keeping us hydrated for longer.

The reason has to do with how our bodies respond to beverages, according to Ronald Maughan, a professor at St. Andrews' School of Medicine and the study's author. One factor is the volume of a given drink: The more you drink, the faster the drink empties from your stomach and gets absorbed into the bloodstream, where it can dilute the body's fluids and hydrate you.

The other factor affecting how well a beverage hydrates relates to a drink's nutrient composition. For example, milk was found to be even more hydrating than plain water because it contains the sugar lactose, some protein and some fat, all of which help to slow the emptying of fluid from the stomach and keep hydration happening over a longer period of time.

Milk also has sodium, which acts like a sponge and holds onto water in the body and results in less urine produced.

The same can be said for oral rehydration solutions that are used to treat diarrhea. Those contain small amounts of sugar, as well as sodium and potassium, which can also help promote water retention in the body.

"This study tells us much of what we already knew: Electrolytes -- like sodium and potassium -- contribute to better hydration, while calories in beverages result in slower gastric emptying and therefore slower release of urination," said Melissa Majumdar, a registered dietitian, personal trainer and spokeswoman for the Academy of Nutrition and Dietetics who was not involved in the study.

Sugar in moderation

But here's where it gets tricky: Beverages with more concentrated sugars, such as fruit juices or colas, are not necessarily as hydrating as their lower-sugar cousins. They may spend a little more time in the stomach and empty more slowly compared to plain water, but once these beverages enter the small intestine their high concentration of sugars gets diluted during a physiological process called osmosis. This process in effect "pulls" water from the body into the small intestine to dilute the sugars these beverages contain. And technically, anything inside the intestine is outside your body.

Juice and soda are not only less hydrating, but offer extra sugars and calories that won't fill us up as much as solid foods, explained Majumdar. If the choice is between soda and water for hydration, go with water every time. After all, our kidneys and liver depend on water to get rid of toxins in our bodies, and water also plays a key role in maintaining skin's elasticity and suppleness. It's the cheapest moisturizer you'll find.

While staying hydrated is important -- doing so keeps our joints lubricated, helps prevent infections, and carries nutrients to our cells -- in most situations people don't need to worry too much about how hydrating their beverages are.

"If you're thirsty, your body will tell you to drink more," Maughan said. But for athletes training seriously in warm conditions with high sweat losses, or for someone whose cognitive function may be negatively impacted by working long hours without beverage breaks, hydration becomes a critical issue.

Can beer and lattes keep me hydrated?

Alcohol acts as a diuretic, which causes you to pass more urine, so when it comes to alcoholic beverages hydration will depend on a beverage's total volume. "Beer would result in less water loss than whiskey, because you are ingesting more fluid with beer," Maughan said. "Strong alcoholic drinks will dehydrate, dilute alcoholic drinks will not."

When it comes to coffee, how well your java hydrates you will depend on the amount of caffeine you consume. A regular coffee with about 80 milligrams of caffeine -- roughly what you would find in 12 oz. of Folgers' house blend -- would be pretty much as hydrating as water, according to Maughan's research.

Consuming more than 300mg of caffeine, or about 2-4 cups of coffee, could cause you to lose excess fluid as the caffeine causes a mild, short-term diuretic effect. This is more likely to happen with someone who doesn't typically consume caffeine, and it could be offset by adding a tablespoon or two of milk to your cup of joe.