This is a "sort-of" fence. Our garden has a wood boarder, old 2 x 6's that we nailed together. It is sort of a raised bed now but the dirt is a foot below the boards. Then we screwed wooden stakes 5 feet high to the wood boarder and strung deer netting all around. We stapled the deer netting to the stakes and to the border on the bottom. For the gate I cut an opening then wove a thick piece of bamboo, the kind you use for a house plant stake, through one side. Then I use a piece of wire top and bottom to hold the gate shut.
This way we remove the deer netting after the garden is dead and the chickens can still play in the garden the rest of the year. And it was cheap...
I think I will put a fence around my garden next spring. I'm going to try a decorative fence about 3 feet tall, but I'm afraid that they'll end up flying over it... Who knows, maybe my garden will end up being a chicken run like the photo above!
As others have said, fence is really the only way I know of - they will find what you don't want them too eventually! Unless you put them in tractors (portable bottomless pens). I have all mine in pasture pens with coops on top so they don't get all mixed up and ruin my breeding program, but it also serves to keep them out of trouble.