How to Stop Your Dog from Running Out of the Backyard
To stop your dog from running out of the backyard, start by inspecting your fence for any areas your dog can jump over or dig underneath. If your dog is crawling under the fence, consider putting large stones around the foot of it or burying chicken wire along the perimeter. However, make sure that any sharp edges on the wire point away from the inside of the fence so your dog doesn't injure itself. Additionally, play with your dog in the yard as much as you can, and call it back to you when it gets close to the edge of the property to reinforce the boundaries.
Determine if your dog escapes due to fear. Your dog may be trying to escape from something that is scaring him. This will usually be in response to something noisy, like a loud car or construction. It may also be something visual, like a bright light or a person walking by the yard.  If you identify the thing responsible for your dog's fear, and it is possible to do so, remove it. Try to limit exposure to the event that causes a fear based escape. For instance, bring your dog inside if a loud bell or siren scares him. Watch your dog to see where he likes to hide when scared. Try to create a similar “safe space” for him in the yard and in the house. Try desensitizing your dog to the fear stimulus. Starting small and gradually increasing exposure to the stimulus over time can result in the loss of fear to that stimulus. Talk with your veterinarian or local dog trainer to learn more. See if your dog is looking for a mate. At around six months old, dogs will begin to look for mates. This drive can be quite powerful. Male dogs are more likely to try to escape if they smell a bitch in heat. Unfortunately for the owner of the male dog, they are able to detect the pheromones (chemical messengers) over a distance of mile. Female dogs are less likely to wander due to hormonal reasons. Female dogs come into heat twice a year, and if you own a female dog, your main concern is other dogs getting in, rather than her out!  The best way to prevent this is to have your dog spayed or neutered. Spaying your dog will prevent her from becoming pregnant if she escapes. Look for signs of separation anxiety. Your dog may simply miss you. Separation anxiety is caused when you leave your dog's presence and his attachment to you causes them anxiety. He may try to escape in an effort to follow you. If your dog usually escapes right after you leave, there is a good chance separation anxiety is to blame. Act calmly when coming home or leaving. By showing your dog that your departure and arrival are not something to be excited about, he should learn to relax during these times. Think about giving your dog an over-the-counter medication, or asking your vet for a prescription, that will reduce anxiety. Even if you use an over-the-counter medication, consult with your veterinarian before use and follow all directions. Make your yard exciting. Your dog may simply be bored, he might be wandering in search of something exciting and new to do. By keeping your yard interesting and engaging, you will make escape less appealing to your dog. Make sure there are plenty of toys in the yard. Play with your dog in the yard. Besides using up energy, your dog will associate the yard with activity and play. Leave food and water out if the dog is outdoors for extended periods of time. See if your dog is jumping the fence. Dogs can be quite agile, and if your fence isn't high enough or offers some footholds, he can jump over top of it. Try the following to make it difficult for your dog to hop over your fence: Check the areas near the fence. Look for any objects that your dog could be using to get over the fence. It may be a chair or some potted plants, with just enough height to help your dog make the jump. Move them away from the fence. Install a fence extension. You can try to make your fence taller if your dog seems to be big enough to jump over by himself. When you add the extension, try to slant the new addition inwards at about a forty-five degree angle. This will make it very difficult for your dog to make the leap. Look for signs that your dog digs under the fence. Sometimes, dogs will take the low road, and dig under a fence to escape. There are a few methods you can use to reinforce your fence and make any attempts at burrowing more difficult for your dog. Dig down and place chicken wire below the fence. Make sure to point any sharp edges outwards, away from the inside of the fence, to prevent injury to your dog. Try putting large stones around the foot of the fence. By putting these stones in place, your dog will be unable to dig close to the fence and escape. If you install a chain link fence, make sure to leave enough height to put some of it underground. This will make an escape by digging difficult, as your dog will have to dig down quite far to break free. Look for any other small gaps he may be squeezing through and cover them up. Inspect the fence for holes caused by chewing. Sometimes dogs can gnaw his way through a fence or other barrier you have put around them. This can not only be dangerous for your dog, but can be an expense as well. Your best option is to figure out what is triggering your dog's escapes and alter that. Install a fence made from a material that is hard to chew through. Sturdy wood or metal can be good options, but if your dog chews them, it may prevent a health hazard. Make your yard exciting. By keeping your yard engaging for your dog, you make it hard for him to want to leave in the first place. By keeping your yard secure, you make it hard for him to leave even if he wants to. Play with your dog often in your yard. If your dog strays to the edges of the property, call them back. By playing and learning the boundaries, he will be more inclined to stay close to home. Keep plenty of toys and play things in the yard. If your dog is outside for a long time, add food and water to prevent escapes based on a search for these things. Make any fence tall enough so that it cannot be jumped over. Also check that it runs deep enough so that your dog cannot dig underneath and escape. Teach your dog basic obedience. Work with your dog to teach them some basic commands. The most useful commands you might want your dog to learn are “come” or “sit”. This will allow you to have your dog return directly or at stop to sit, if he escapes. Don't punish fear or anxiety based escapes. If your dog suffers from anxiety when you leave him alone, punishing your dog will not help him relax. Try instead to help your dog overcome anxiety that is cause by your departure. Punishing and anxious dog will only help to increase fear. Conversely, do not reassure your dog when it is exhibiting anxious behavior, as this will reinforce the anxiety. It is best to simply ignore any unwanted, anxious behavior from your dog. Never discipline your dog after an escape. Once your dog is free of the fence, any punishment will become associated with wherever he might find himself at that moment. Only discipline your dog if you catch them in the act of escape.  Punishing after escape will not teach your dog that escape itself is wrong. Disciplining your dog after you catch him will only make him fearful of you. Catching him again will become more difficult as he may try to run away from you. Catch your dog in the act. If you are able to catch your dog as it tries to escape, you may take disciplinary action. You will have to be careful to discipline him in a way that he will associate only with the escape, not with you. Try taking and action that your dog won't associate with you. Spray your dog from a distance using super-soaker type water pistol so your dog won't see you coming. If your dog sees you as the cause behind the unpleasant disciplinary action, he will associate with you alone. Now your dog will simply wait for you to leave before going back to his escape plans. 
Determine if your dog escapes due to fear. See if your dog is looking for a mate. Look for signs of separation anxiety. Make your yard exciting. See if your dog is jumping the fence. Look for signs that your dog digs under the fence. Inspect the fence for holes caused by chewing. Make your yard exciting. Teach your dog basic obedience. Don't punish fear or anxiety based escapes. Never discipline your dog after an escape. Catch your dog in the act. 