Well, it's not guaranteed. Some dogs never grasp the need to obey, but...
When I first get any dog I use a really long lead, like 25 feet. I'll walk them around the perimeter of the property when I take them out, then I'll let them wander a bit in the yard. When they reach the edge of no-dog's-land, they get a tug on the lead. With some dogs even this isn't necessary, they just pick up quickly where the pack's real estate ends. OTOH, you may get a knucklehead like my Aussie who generally does stay in the yard and knows where the limits are but ill break it if he sees another dog (he loves all dogs). Him I have to watch. The two females I've done this with I don't even have to keep an eye on. My Black Dog simply won't leave the yard limits, even if chasing a critter that has trespassed. Stops at the property line. Maybe I'm just lucky with the dogs I wind up with.

