A lot of people think that a wagging tail means a dog is showing his friendliness, but that belief could quickly get you into trouble. In reality, not all 'wags' mean the same thing.
One wag may indeed be signaling a "Hello friend!" welcome, but another wag might be telling you to "Back off!" while yet another is saying "I'm frightened!" How do you tell the difference? Here's a primer to help figure it out:
HEIGHT OF TAIL: The height that the dog holds its tail is kind of like an emotional thermostat. The higher the tail, the more alert the dog is. A mid-height tail would suggest the dog is alert but relaxed. A low slung tail indicates fear.
SPEED OF WAG: The speed of the wag indicates the level of excitement the dog is feeling. The faster the wag, the higher the stimulation.
DISTANCE OF WAG: The distance the tail travels when wagging indicates whether the dog's emotional state is positive or negative. The greater the distance traveled back-and-forth, the more positive the emotional state.
Now here are three important things to keep in mind:
Dogs communicate their emotional state in more ways than just tail-wagging, so the most accurate indication of a dog's emotional state is to factor-in the dog's other 'body language' signals and/or vocalizations.
Some breeds naturally carry their tails at a different height than other breeds. For example, it's common for Beagles to have a very upright tail, and for Akitas to have an upright and curled tail. Alternatively, it's common for Whippets and Greyhounds to have a very low-slung tail. For these types of breeds you would need to understand what the 'normal' height of the tail is in order to determine what is higher or lower than normal for that dog/breed.
It can be very difficult (if not impossible) to figure out the 'wag' of a dog that has a docked tail, so knowledge of dog 'body language' signals becomes all the more important to determine its emotional state.