Dogs bark because we humans want our dogs to bark. For years our domestication process and selective breeding has allowed our dogs to develop their barking abilities. Wolves don't bark. Barking was further developed in dogs in order to scare intruders or to help the master out (i.e. on farms to assist in gathering the sheep).
Most dogs simply bark to communicate, to get attention, or simply to show their excitement. Training and lifestyle are important factors in teaching the dog how to communicate with its master. If you reward your dog for barking, he will continue to do so. The best thing is to figure out what your dog is trying to tell you and go from there.
If you have a dog that barks excessively, try to figure out what he is trying to tell you. If it is out of need for attention, the way to break the cycle is to wait for him to be quiet and then give him the attention he needs. By acknowledging the barking, you reinforce it. Waiting until he quiets will teach him that he gets attention when he is not barking.
Some dogs are extremely territorial. They will bark at not only a person approaching, but someone they see walking across the street or on the next block. The best way to stop this is to distract him when he starts to bark. Catch his attention with a treat or by playing. Every time the bark cycle is broken, it sends the message that quiet will get the most reward.
Taking the time to discover what your dog is communicating will result in less stress for both you and him. He will get much needed attention and you will get quiet. It’s a situation you both win.