When a dog that was previously housebroken suddenly starts having accidents, it's important to look for a physical cause. Bladder infections are common, particularly in female dogs. Kidney stones can cause straining and spotting for many male cats. Older pets may "leak" a little in their sleep. Diabetes may mean your pet is drinking more, and consequently urinating more than he used to. If your pet is having accidents, it's important to rule out a physical problem with a trip to the vet. Most of these problems can are treatable once they are diagnosed, but a few are life threatening if ignored.
If you've ruled out all physical causes for your pet's problem, the issue may be poor communication. For dogs to make the connection between one thing and another, any input has to be immediate. If you catch your dog in the act of eliminating in an inappropriate spot, tell him "NO!" in a firm voice, immediately take him to where you do want him to go and praise him if he does. However, if you come home to piles and puddles, or if your puppy goes when you aren't paying attention, it's too late to do anything about it. Simply clean up and resolve to pay closer attention next time.
Taking your pet to the scene of the crime and "showing" her the mess does not effectively communicate what you want. Your pet may act "guilty," but what we see as guilt or contrition is actually just submissive behavior. By cowering down and lowering her head, she's acknowledging that you're the boss and that she knows you're upset. The problem is that she doesn't know what she did wrong. For more information about effective dog training, see How Dog Training Works.
When a dog seems to be sneaking off to soil the house, there are two main causes. If a dog has been caught and corrected for eliminating in the house, she will learn that she's not allowed to go in front of you, but she may not understand that you don't want her to go in the house at all. She will think she's obliging you by going off and taking care of it privately. This problem comes from correcting the dog without adequately rewarding her for performing correctly.
The other primary cause of this behavior is that the dog does not identify all parts of the house as "den" and therefore off limits for elimination. She's looking for an unused or remote location, as far as possible from the main living space. In both cases, the solution is to close off areas of the house where you can't supervise, take the dog out often and heap on the praise when she goes where she's supposed to.
Sometimes the problem is that we've trained our dogs to do something we didn't intend. Giving a dog a treat when they come inside after a successful potty break falls into this category. You've actually rewarded the dog for coming inside, not for eliminating outside. Dogs that have learned they get a cookie when they come in may be reluctant to stay outside and eliminate. Typically, verbal praise when the dog is outside in the act is more effective than food rewards, but if you want to give a food reward, offer it when the dog is still outside.
Some dogs are harder to housebreak than others are. Dogs that come from situations where they were unable to escape their own waste, such as puppy mills, may have lost the natural inclination to stay clean. They just go wherever they are because that's what they were forced to do. You can still housebreak puppy mill dogs using all the same techniques we have discussed, but it will take longer. Some of these dogs may never be completely reliable left unattended in the house, but with careful training, you can minimize accidents.
Small and toy breed dogs may be more difficult to housebreak than larger dogs. Many small breed dogs come from puppy mill or pet store situations like those described above, or they may come from homes where they were allowed to go the bathroom wherever they pleased. In either case you're not starting from scratch, you've got to help them unlearn bad habits while you're teaching new ones. Use the same techniques but expect progress to be slower.
It may be harder for a tiny dog to see the entire house as "den" space because it's so big relative to them. Tiny dogs also have tiny bladders and simply can't hold it as long as bigger dogs can; they will need more potty breaks to avoid accidents.
If you have a small dog and are gone all day, it may be kinder to restrict him to one room and train him to use a pad or newspaper in your absence, just as you would with a young puppy.
Among animals that are physically capable of being housebroken, the process is relatively straightforward; you just need to train a preference for a certain substrate. Praise your pet for following the rules, try to minimize accidents, correct promptly if they occur and give your pet an opportunity to go in the proper place. How long it takes will depend on your pet's size, age, and background. But more than anything it will depend on your consistency. A little extra effort in the beginning will pay off down the road!
For lots more information on housebreaking and related topics, check out the links below.