Dogs bark for many reasons. They might bark when they're left alone for hours at a time, either because they want their owners to return or because they have too much pent-up energy, or you may have accidentally trained your dog to bark by giving it attention when it does. Whatever the reason for your dog's barking, you can train it to break the bad habit, but you should know that it could take some time.
If you think your dog may bark out of boredom because of pent-up energy, you need to make sure the dog gets plenty of exercise during training. Just letting dogs out in the backyard may not be enough. Dogs are very social creatures and they need interaction with you or other dogs during exercise, so taking your dog on a regular walk may help curb barking.
According to the Iowa City Animal Center, you can sometimes train smaller dogs to stop barking by saying "no" in a loud, commanding voice each time they bark, but bigger dogs often need structured training. However, you can try structured training sessions with any dog. During structured training sessions, remember to be patient with your dog and focus on praise when it obeys your command. When your dog starts barking, say, "be quiet" and hold a treat in front of its nose. Your dog will stop barking because it can't smell or lick the treat while barking. After three seconds of silence, give the dog the treat and praise it. Your dog will probably not obey your command every time you try this exercise, especially at first. When your dog doesn't obey, reprimand it by making a loud noise (such as clapping) or squirting a small amount of water at it, but never hit your dog. When your dog does obey your command, reward it instantly. As your dog begins to obey your command more regularly, you can increase the amount of time you require it to be quiet before you give it a treat. It will take time, but try to work up to a minute or two. Eventually, your dog will obey your command without the treat incentive.