A fence can do any of these things — if you choose the right one. There are hundreds of different styles to choose from, plus a handful of different construction materials, each with their own maintenance requirements and prices.

And you’ll need to make sure your fence doesn’t create animosity in the neighborhood — or even violate local laws and regulations. Here’s how to avoid those pitfalls and get a beautiful long-lasting fence that fits your home and your budget.

Follow the rules

Fences are subject to local zoning codes, which dictate the maximum height allowed, how far they must be from property lines, and whether they’re even permitted in front yards. So contact your municipality’s zoning department first, suggests Janet Arden, of the American Fence Association, a trade group based in Glen Ellyn, Ill.

Also, if you’re in a neighborhood association, a historic district, or a fairly new development, you may face further limitations on fence style, height, and location — so check with local officials.

Be a good neighbor

As Robert Frost wrote, good fences make good neighbors — but they can also make angry ones if the fence appears one day without warning. If possible, consult with any neighbors whose property will abut your new fence to give them a chance to prepare emotionally for the change. (Heck, they might even offer to share the cost if you compromise on some design feature that they prefer.)

Also, unless you’ve had your lot surveyed, ask your neighbors to confirm your understanding of where the property lines are, says Roy Cuzzocreo of Orange Fence & Supply in Orange, Conn. “I’ve had to come back to relocate an entire fence by an inch and a half because the homeowner was wrong about the property line,” he says.

Consider your goals

The first thing any fence salesman is going to ask you is why you want a fence—because your answer will help narrow your choices. There are four basic categories to choose from:

Privacy fence: If the goal is to block sight lines, you need solid fencing, which generally means it’ll have tightly spaced vertical boards, pickets (pointed stakes), or framed panels to prevent you from seeing out and others from seeing in. It should be at least 6 feet tall so most people won’t see over it—taller if the neighbor’s teenagers are on the basketball team.

If a little visibility is okay, then the pickets can have spaces between them, or you can use a lattice or decorative fence pattern.

Security fence: To keep people out, you’ll again want a fence that’s 6 feet tall or higher to hinder anyone from simply hopping over it. Pickets or other spiky tops help to deter climbers—especially if the fence has a smooth outer face, so there’s no place to step. For fences with horizontal rails on one side and vertical pickets on the other—in other words, for most fences—that means facing the pickets out.
 
Decorative fence: If the goal is to establish property lines, add a structural element to the landscape or boost curb appeal, your fence doesn’t need to be nearly as large or obtrusive. You can choose one that’s just two to four feet high, and with spaced pickets, latticework, or all sorts of ornamental designs that don’t block the view, but enhance it. Or you can go totally simple, with a rail fence (just posts and two or three horizontal members) like the ones used on horse farms.

Safety fence: To create a dog run, enclose a pool area, or deter wildlife from trespassing on your property—without changing the view—the most durable option is a wire fence, such as chain link. At their most economical, these consist of galvanized metal mesh, but adding a black or green vinyl coating helps to make the fence almost disappear from view. Or, for an even lower-cost fence, you can use a metal or plastic mesh hung on metal posts or stakes.

Pick your material

Once you’ve decided on your fence type, choose the material it’s made from. That’s what’s going to determine its price, the maintenance it needs, and its warranty. (Note: These are ballpark prices. Costs vary wildly around the country—and even among fence companies in the same ZIP code.)

Wood: By far the most common fence material, wood provides a traditional look at a moderate price. Depending on the species you choose, from low-cost pine to high-end cedar or redwood, your installer may recommend treating it with a stain or wood preservative to protect it from insects, rot, and ultraviolet light. Expect to repeat the job every three to five years.

Cost: $7 to $10 per foot, installed, for a simple split-rail fence; $20 to $50 per foot, installed, for a 6-foot high privacy fence.

Warranty: From 0 to 15 years depending on wood species and the retailer.

Vinyl and composite: These faux-wood fences are made from either solid vinyl or a mix of wood fibers and plastic resins. In either case, the material is formed into rails, pickets, and other fence parts that get assembled piece-by-piece just like wood fences.

Their color—usually white, but available in numerous hues—is mixed into the material itself, so they never need painting. The best of these products look exactly like the real thing, so if you want a painted wood fence, this is a way to get it without all of the maintenance that wood requires.

Cost: $40 to $60 per foot per foot, installed, for a 6-foot high privacy fence.

Warranty: From 20 years to lifetime, depending on manufacturer.

Iron and aluminum: The classic wrought-iron fence can be anything from an ornate decorative property-line marker to a tall, spiky enclosure that provides high security.

These days, though, the fences aren’t actually wrought iron. They’re made from welded tubes of steel or aluminum. Thanks to factory paint coatings, a good metal fence will need virtually no routine upkeep, though you should touchup any spots where the coating cracks or peels to prevent corrosion.

Cost: $25 to $30 per foot installed (for a 4 foot high fence), plus $5 to $10 per foot to add ornamental finials and rings.

Warranty: From 20 years to lifetime, depending on manufacturer.

Chain link and wire: The most economical of fences, chain link also has the advantage of almost disappearing into the scenery, especially if it has a black or green plastic coating on the mesh.

If, on the other hand, you prefer not to see through the fence, you can order it with vertical privacy slats woven into the mesh.

Cost: $12 to $15 per foot installed (for a 4 foot high fence); add $4 to $5 for vinyl coating and another $6 to $10 for privacy slats.

Warranty: From 12 to 15 years, depending on manufacturer.