{
  "id": "fence",
  "version": "638ba5eb5dc6",
  "status": "published",
  "name": "Fence Calculator",
  "question": "How much fence material do I need?",
  "summary": "Counts the posts, rails and pickets for a fence from its length, post spacing, rails per section and picket width and gap, with the material cost when you add prices.",
  "category": "construction",
  "subcategory": "materials",
  "url": "https://www.acalculator.org/construction/fence-calculator",
  "markdown": "https://www.acalculator.org/construction/fence-calculator.md",
  "kind": "function",
  "method": "Sections = ⌈length ÷ post spacing⌉; posts = sections + 1; rails = sections × rails per section; pickets = ⌈length × (1 + extra ÷ 100) ÷ (picket width + gap)⌉; cost = posts × post price + rails × rail price + pickets × picket price.",
  "assumptions": [
    "One straight run with a post at each end. Each corner or gate adds posts; work out each straight side on its own and add them.",
    "Each rail spans one section, so buy rails at least as long as the post spacing.",
    "Defaults: posts 8 ft apart and 3 rails, as fence makers suggest for a 6 ft privacy fence (NMI Fence); 5½ in pickets (a 1×6 board) with no gap; 5% extra pickets."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "l": {
        "title": "Fence length",
        "description": "The total length of the fence line.",
        "type": [
          "number",
          "string"
        ],
        "x-quantity": "length",
        "minimum": 0.1,
        "maximum": 10000
      },
      "sp": {
        "title": "Post spacing",
        "description": "The distance between post centres: 8 ft is common, 6 ft for tall or heavy fences.",
        "type": [
          "number",
          "string"
        ],
        "x-quantity": "length",
        "minimum": 0.3,
        "maximum": 5
      },
      "r": {
        "title": "Rails per section",
        "description": "Horizontal rails between each pair of posts: 2 for a low picket fence, 3 for a 6 ft privacy fence.",
        "type": "integer",
        "minimum": 0,
        "maximum": 6
      },
      "pw": {
        "title": "Picket width",
        "description": "The actual width of one picket: a 1×6 board is 5½ in wide.",
        "type": [
          "number",
          "string"
        ],
        "x-quantity": "length",
        "minimum": 0.01,
        "maximum": 1
      },
      "gap": {
        "title": "Gap between pickets",
        "description": "The space left between pickets: 0 for a privacy fence.",
        "type": [
          "number",
          "string"
        ],
        "x-quantity": "length",
        "minimum": 0,
        "maximum": 1
      },
      "x": {
        "title": "Extra pickets",
        "description": "Pickets to add for cuts and bad boards, in percent.",
        "type": "number",
        "x-unit": "percent",
        "minimum": 0,
        "maximum": 100
      },
      "pp": {
        "title": "Price per post",
        "description": "What one post costs. Leave all three prices empty to skip the cost.",
        "type": "number",
        "x-unit": "USD",
        "minimum": 0,
        "maximum": 100000
      },
      "rp": {
        "title": "Price per rail",
        "description": "What one rail board costs.",
        "type": "number",
        "x-unit": "USD",
        "minimum": 0,
        "maximum": 100000
      },
      "kp": {
        "title": "Price per picket",
        "description": "What one picket costs.",
        "type": "number",
        "x-unit": "USD",
        "minimum": 0,
        "maximum": 100000
      }
    }
  },
  "outputs": {
    "posts": {
      "label": "Posts",
      "description": "Sections + 1: one post at each end and one between each section.",
      "format": "integer"
    },
    "sections": {
      "label": "Sections",
      "description": "Fence length ÷ post spacing, rounded up.",
      "format": "integer"
    },
    "railCount": {
      "label": "Rails",
      "description": "Sections × rails per section.",
      "format": "integer"
    },
    "pickets": {
      "label": "Pickets",
      "description": "Fence length × (1 + extra ÷ 100) ÷ (picket width + gap), rounded up.",
      "format": "integer"
    },
    "cost": {
      "label": "Material cost",
      "description": "Posts, rails and pickets times their prices.",
      "format": "money"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "l": 30.48,
      "sp": 2.4384,
      "r": 3,
      "pw": 0.1397,
      "gap": 0,
      "x": 5
    },
    "outputs": {
      "posts": 14,
      "sections": 13,
      "railCount": 39,
      "pickets": 230
    },
    "text": "A 100 ft fence with posts 8 ft apart needs 14 posts, 39 rails and 230 pickets."
  },
  "examples": [
    {
      "given": {
        "l": 30.48,
        "sp": 2.4384,
        "r": 3,
        "pw": 0.1397,
        "gap": 0,
        "x": 0
      },
      "expect": {
        "sections": 13,
        "posts": 14,
        "railCount": 39,
        "pickets": 219
      },
      "source": "NMI Fence, Fence Post Spacing Guide (privacy fence: posts 8 ft apart, 3 rails on fences 6 ft and taller; picket fence: 8 ft, 2 rails), https://nmifence.com/blog/fence-post-spacing; Extreme How-To, How To Build a Wood Fence (posts no wider apart than the rails, usually 6 to 8 ft on center), https://extremehowto.com/diy-privacy-fence/; hand calculation in content.mdx: 100 ÷ 8 = 12.5 → 13 sections; 1,200 in ÷ 5.5 in = 218.2 → 219 pickets"
    },
    {
      "given": {
        "l": 29.260800000000003,
        "sp": 2.4384,
        "r": 2,
        "pw": 0.08889999999999999,
        "gap": 0.0635,
        "x": 0,
        "pp": 12,
        "rp": 6.5,
        "kp": 2.25
      },
      "expect": {
        "sections": 12,
        "posts": 13,
        "railCount": 24,
        "pickets": 192,
        "cost": 744
      },
      "source": "NMI Fence, Fence Post Spacing Guide (privacy fence: posts 8 ft apart, 3 rails on fences 6 ft and taller; picket fence: 8 ft, 2 rails), https://nmifence.com/blog/fence-post-spacing; hand calculation in content.mdx: 96 ÷ 8 = 12 exactly; 1,152 in ÷ 6 in = 192; 156 + 156 + 432 = $744"
    },
    {
      "given": {
        "l": 30,
        "sp": 2.4,
        "r": 3,
        "pw": 0.14,
        "gap": 0.01,
        "x": 10
      },
      "expect": {
        "sections": 13,
        "posts": 14,
        "railCount": 39,
        "pickets": 220
      },
      "source": "Extreme How-To, How To Build a Wood Fence (posts no wider apart than the rails, usually 6 to 8 ft on center), https://extremehowto.com/diy-privacy-fence/; hand calculation in content.mdx: 30 ÷ 2.4 = 12.5 → 13; 30 × 1.1 ÷ 0.15 = 220 exactly"
    }
  ],
  "sources": [
    "NMI Fence (National Metal Industries), Fence Post Spacing Guide: wood privacy fence posts 8 ft apart with 3 rails on fences 6 ft and taller; picket fence 8 ft with 2 rails. https://nmifence.com/blog/fence-post-spacing (retrieved 2026-10-01)",
    "Extreme How-To, How To Build a Wood Fence: space posts no wider than the rails, usually 6 to 8 ft on center. https://extremehowto.com/diy-privacy-fence/ (retrieved 2026-10-01)",
    "NIST Handbook 44, Appendix C, General Tables of Units of Measurement: 1 ft = 12 in = 0.3048 m. https://www.nist.gov/document/2026-nist-handbook-44-appendix-c (retrieved 2026-10-01)"
  ],
  "related": [
    "deck",
    "square-footage",
    "concrete"
  ],
  "changelog": []
}
