K-9 Communication
In terms of evolution, there has to be a reason for barking, or it probably wouldn't be there. Is it to warn of predators? But dogs bark when there are no predators around. Is it play? Some dogs play without barking. In fact, people who study canine behavior find there isn't much of a pattern to barking--it seems to be an all-purpose noise.
Now here's another fascinating thing: adult wolves don't bark. They growl, they whine, and they howl, but no barking. And dogs evolved from wolves. So where did the bark come in?
Mark Feinstein and Ray Coppinger at Hampshire College in Massachusetts came up with a theory. These biologists have noted that while adult wolves don't bark, adolescents do. Wolf pup barking seems to be an intermediate noise they grow out of.
More Bark Than Bite
Now, a few tens of thousands of years ago, wolves and people started becoming friendly species. You can imagine a person tossing a bone to a friendly wolf from time to time. But "friendly" is the key. Nobody ever gets close to a hostile wolf. So over many thousands of years we would gradually have been selecting for certain behavioral traits: playfulness, low hostility and the ability to bond very puppy-like behaviors).
A species that resembles a wolf puppy that never grows up may slowly have evolved in this way. That species would retain its puppy-like behaviors, such as barking, but never grow into growling, howling adult wolves. That species we would now call "dogs."
Read More:
"Why Do Dogs Bark?" (U.S. News and World Report)