Wolves, the ancestors of domestic dogs, also wag their tails, especially when greeting.
Sara Marshall-Pescini, a senior researcher at the Lorenz Ethology Institute, explains: this behavior often occurs when wolves reunite after a separation. In a wolf pack, there is usually a pair responsible for breeding and other adult individuals who help care for the offspring.
Wagging the tail can indicate submission: when a wolf holds its tail low and moves it side to side, it shows its status in the pack. This behavior helps avoid conflicts over resources.
Puppies, when greeting adults, also wag their tails and lick their parents' cheeks, which encourages them to regurgitate food for the young.
Dogs have adopted these greeting signals from wolves and use them when communicating with humans. If a dog tries to lick your face, it is certainly not very hygienic. However, wagging the tail remains an important sign of friendliness and affection.