Barking is a natural function for a dog and a dog is only doing what is normal for any dog to do when it barks.
However when a dog lives with humans we do not always appreciate barking in certain circumstances or non-stop barking.
Barking while playing or when strangers appear are perfectly acceptable behaviours in most circumstances.
To prevent excessive or nuisance barking you need to train your dog as to what you appreciate and what you do not want him to do.
Start by commanding your dog to stop barking when you tell him.
If he will not stop barking when you tell him to, then make a loud noise to distract him.
If he stops barking when told to, always reward him for his quiet behaviour.
Often there is a reason for a dog barking where rectifying the cause will solve the problem, For example your dog will not appreciate being placed in a pen in a back yard and left alone and you can hardly blame him for that.
If you need to use an outside pen for your dog, then at least place it in a position where he will not feel isolated.
Better still if your dog is not allowed in your house, fence in your property so that he can roam freely in the yard.
Sometimes there is a problem of barking when you attempt to put the dog to bed.
Try giving him a special treat that he can look forward to at bedtime such as a chew toy.
If the dog sleeps in the house another solution is to move his bed into your bedroom.
If the dog sleeps outside you will need to train him by rewarding him for successively longer periods of quiet behaviour.
Exercise close to bedtime can also help as this will tire the dog more quickly and after all he cannot bark while asleep.
Hopefully all these tips will work but there are more steps that can be taken to stop unwanted barking.
There is a product called a citronella collar, which works by spraying a squirt of citronella, that dogs do not like when ever the dog barks.
There are situations where perhaps a neighbour is complaining to local city authorities and urgent action is needed.
An absolutely last resort is surgical de-barking and you need to talk to your veterinarian about the pros and cons of this, but please first look at all other options available.
Remember barking is a natural function for your dog.