Deck Railing Calculator
Enter the railing length, post spacing and per-foot material cost to estimate posts, sections and total cost.
What you get
Three outputs from two inputs. Sections is how many bays of railing you build, posts is how many vertical supports to set, and total cost is the material price of the railing. At the defaults, 40 ft of railing at 6 ft spacing gives 7 sections, 8 posts and $1,000 of material. Posts and sections matter before you order because the code limits how far apart the posts can be.
Why the sections round up
Spacing is a maximum, not a target. Forty feet divided by 6 ft is 6.67, and you cannot build two-thirds of a bay, so the count rounds to 7 sections. Each section then ends up 40 ÷ 7 = 5.71 ft long, a little tighter than the 6 ft you entered and perfectly legal.
The extra post is the one people forget. Seven bays need eight posts because both ends of every bay are supported. Ordering 7 posts leaves one end of the run floating, which is a failed inspection and a return trip to the lumber yard.
Code requirements that set the numbers
The International Residential Code requires a guard on any deck more than 30 in. above grade. The guard must be at least 36 in. tall measured vertically from the deck surface, and it must resist a 200 lb concentrated load applied at any point along the top. Those two rules fix the height and the post anchoring, not the material.
The other rule is the baluster gap. Openings in the guard cannot let a 4 in. sphere pass through, and that applies at the bottom rail, between balusters and under any decorative pattern. A 4 in. clear gap means balusters on roughly 4.5 in. centers, which is about 3 units per foot of railing. Forty feet therefore needs around 105–115 balusters, not the 60 or so people estimate by eye.
2026 deck railing cost by material
| Material | Material per ft | 40 ft material | Installed per ft |
|---|---|---|---|
| Pressure-treated wood with wood balusters | $10–$20 | $400–$800 | $25–$45 |
| Composite | $25–$45 | $1,000–$1,800 | $45–$75 |
| Aluminum with aluminum pickets | $35–$70 | $1,400–$2,800 | $60–$100 |
| Cable rail, stainless | $50–$100 | $2,000–$4,000 | $85–$140 |
The $25 default is compositing territory: composite railing material runs $25–$45 per ft, so 40 ft at $25 is the low end of a mid-grade system. Wood at $15 per ft would be $600, and cable rail at $60 would be $2,400. None of these include posts, which are the next consideration.
Posts and hardware are not in the per-foot price
A railing quote per linear foot usually covers rail, balusters and top cap. Posts are separate: a 4 by 4 treated post is $12–$25, a composite sleeve post $35–$70, and an aluminum post $40–$90. Eight posts at $40 averages $320, plus $8–$15 each for post bases, brackets and lag screws. That is another $400–$750 on top of the $1,000 of rail on the default job.
Worked example at the defaults
Forty feet at 6 ft spacing: 40 ÷ 6 = 6.67, rounded up to 7 sections. Posts are 7 + 1 = 8. Cost is 40 × $25 = $1,000 for rail and infill. Add eight posts at $40 and $10 of hardware each, and the real material number is closer to $1,400 before a single fastener goes in.
Change one input and watch what happens. Tighten spacing to 4 ft for cable rail and you get 10 sections and 11 posts on the same 40 ft, a 37 percent increase in post count for a stiffer, safer span. Relax to 8 ft and you get 5 sections and 6 posts, but 8 ft exceeds what most cable systems allow and puts more load on each post.
What moves the number
- Post spacing: going from 8 ft to 4 ft doubles the post count and adds $300–$700 on a 40 ft run
- Material: cable rail costs 4–5 times pressure-treated wood at the same length
- Baluster count: a 4 in. sphere rule means roughly 3 per ft, so 40 ft needs 105–115
- Corners: every corner post carries two rails and needs its own bracket set, about $25–$45 extra
- Stairs: a raked section needs angled brackets and a separate post layout, adding $150–$400
- Height: a 42 in. guard instead of 36 in. adds about 15 percent to rail and post material
Stair railing is its own job
A stair guard follows the rake at roughly 32–37 degrees, so the rails are cut on an angle, the balusters are progressively shorter and the posts must be plumb despite the slope. A handrail on stairs sits 34–38 in. above the nosing line, measured vertically, which is a different measurement from the 36 in. guard on the flat. Budget $150–$400 extra per flight for the hardware and the extra cutting.
Wood, composite or metal
Wood is the cheapest at $400–$800 for 40 ft and needs re-sealing every 2–3 years, about $60–$120 a coat. Composite runs $1,000–$1,800 and never needs finishing, but it fades slightly and cannot be sanded back. Aluminum is $1,400–$2,800 and is the only one of the three that will not rot, warp or need paint in a coastal climate. Over 15 years the composite and aluminum options usually cost less than wood plus four rounds of sealer.
DIY versus a pro
Railing is one of the more forgiving deck projects. The work is repetitive, the cuts are square on a flat run, and a homeowner with a miter saw, a level and a drill can finish 40 ft in 2–3 weekends. Material is $1,000–$1,400, against $2,600–$3,600 installed at $65–$90 per ft, so the labor share is $1,500–$2,200.
The parts that go wrong are layout and post anchoring. Posts must be plumb in both directions, which means shimming or notching rather than forcing the bracket. The first and last posts carry the highest load and need through-bolts or blocking below the deck surface, not just lag screws into the rim. An inspector will pull on the rail; a post that moves under hand pressure fails.
Mistakes that fail inspection
Four failures account for most railing inspection problems. Balusters spaced at 4.5 in. clear instead of 4 in., which lets the test sphere through. A bottom rail more than 4 in. off the deck, which creates the same gap at the bottom. A 34 in. guard instead of 36 in., usually because the deck board thickness was not counted. And posts lagged only into the rim joist with no blocking, which passes a visual check and fails a load test. Fixing any of them after the fact means pulling balusters or adding structure, so measure before you cut.
Frequently asked questions
How far apart should deck railing posts be?
6 ft is the common maximum for wood and composite, and 4–5 ft for cable rail because the cables load each post harder. At 40 ft, 6 ft spacing gives 7 sections and 8 posts.
How many railing posts do I need for 40 feet?
Eight. Forty divided by 6 rounds up to 7 sections, and sections plus one gives 8 posts, because both ends of every bay need support.
How much does deck railing cost?
Material is $10–$100 per linear foot by type, so 40 ft runs $400 for wood to $4,000 for cable rail. Installed, the same run is $25–$140 per ft, or $1,000–$5,600.
What is the standard railing height?
36 in. minimum by the IRC, measured from the deck surface. Some local codes require 42 in., and a 42 in. guard adds roughly 15 percent to rail and post material.
When is a guard rail required on a deck?
When the deck surface is more than 30 in. above grade. Below that threshold a guard is optional, though many homeowners add one anyway for comfort.
How many balusters do I need for 40 feet?
About 105–115. The 4 in. sphere rule sets balusters on roughly 4.5 in. centers, which works out to about 3 per foot of railing.
Can I install deck railing myself?
Yes on a flat run. Material is $1,000–$1,400 against $2,600–$3,600 installed at $65–$90 per ft, so the saving is $1,500–$2,200. Posts must be plumb in both directions and through-bolted, not just lagged.
Do railing posts need blocking?
Yes at the ends and corners. A lag screw into the rim joist alone pulls out under the 200 lb code load. Add blocking or through-bolts, which costs $10–$25 per post in material.
What is the 4 inch rule for deck railing?
No opening in the guard may pass a 4 in. sphere. That applies between balusters, between the bottom rail and the deck, and under decorative panels.
Is composite or wood railing cheaper?
Wood is cheaper up front at $400–$800 for 40 ft against $1,000–$1,800 for composite. Wood needs $60–$120 of sealer every 2–3 years, which closes most of the gap over 15 years.
Method and sources
- Deck railing post spacing and sectioning; guard rail code minimum 36 in height.