DeckMath
railing · guardrail · stair handrail · IRC R312

Railing Linear Feet Calculator

How much railing do you actually need? DeckMath sums perimeter minus house-attached sides minus gates, plus angled stair handrail (hypotenuse), with material-specific post spacing (4-6′ o.c.). 5 tiers from PT cap ($24/lf · DIY) to tempered glass ($105/lf · luxury). Auto IRC R312 guard-height flag + R311.7.8 stair-handrail check.

4 shapes · rect / L / U / custom5 materialsIRC R312 + R311Auto post countBoM + share + PDF
5·Material tiers
4-6′·Post spacing o.c.
36/42″·Guard height
R312·IRC code

Inputs

Deck shape

Main rectangle

ft

ft

Full perimeter56
Open (after attached)40
Guard LF (after gates)40
in

⚠ IRC R312 — 36″ guardrail required.

Stairs

in

in

Hypotenuse / stringer5.48
Handrail LF (all stairs)5.48

Results

IRC R312 guardrail required (36″) · IRC R311 stair handrail required · DIY tier 1

Total railing
order 48.66′ (7% waste)
Posts
6′ max o.c.
Project total
Low $3,852 · Northeast
$/lf installed
Low $85

Perimeter diagram

1612house1 stair
Railing required (40′) House-attached (no rail) Stair (5.48′ handrail)

Guardrail required — 36″ off grade ≥ 30″

IRC R312.1.1 + R312.1.2

IRC R312.1.2 mandates a 36″ minimum guardrail on the open sides of decks more than 30″ above grade. 40 LF of guardrail in the BoM.

Stair handrail required — 5 risers ≥ 4

IRC R311.7.8.1 + R311.7.8.4

IRC R311.7.8.1 requires a handrail on at least one side of stairs with 4+ risers. 5.48′ hypotenuse per side · one side × 1 stair = 5.48 LF of angled handrail. Returns at top + bottom (R311.7.8.4) included as bracket-kit line item.

Post spacing — max 6′ o.c. (10 posts total)

IRC R312.1.4 + manufacturer spec

6′ max post spacing meets IRC R312.1.4 + manufacturer spec. Composite sleeves slip over a 4×4 PT structural post.

4″ sphere rule — opening limit verified

IRC R312.1.3.1 + R312.1.3.3

IRC R312.1.3.1 requires that a 4″ sphere cannot pass through any guardrail opening. Baluster centers at ≤4″ (use the Baluster Spacing Calculator to size individual baluster placement once total LF is set). Stair triangle (R312.1.3.3) limited to 4-3/8″ — handrail brackets account for this.

Material tier 1 — DIY-friendly

Manufacturer install spec

Best value mid-market. Color-matched cap, 25-yr warranty, no repaint. DIY-friendly w/ pre-cut kits.

Composite cap rail w/ aluminum balusters (Trex Signature / TT Classic)
49 lf ordered · 45 lf actual · 7% waste · $42/lf installed-equiv
49 lf
$2,044
Composite-sleeve 4×4 posts (matching cap)
10 posts · 8 guard + 2 stair posts · max 6′ o.c.
10 post
$850
Surface-mount post bases (Simpson APB / DTT2Z)
10 post bases bolted through decking into framing
10 ea
$260
Stair handrail brackets + returns (IRC R311.7.8.5)
4 brackets · code-compliant 1.5″ wall clearance · returns at top/bottom
4.0 ea
$56
Materials subtotal
$3,210

Cost breakdown

Materials
$2,953 – $3,210
Labor
$899 – $1,099
Soft costs
$0 – $0
Subtotal
$3,852 – $4,308
Contingency (8%)
$345
Project total
$3,852 – $4,653
Cost per linear foot (45.48 lf)
$85 – $102

2026-Q1 pricing. Ranges reflect contractor vs DIY purchase, regional supplier variance, and the 7% material waste typical of composite cap rail w/ aluminum balusters (trex signature / tt classic). Permit fees are average residential — your local AHJ may charge more. Always verify code with your local inspector before ordering.

How to use

Three steps. Permit-ready output.

  1. 01

    Pick the deck shape

    Rectangle (most common — 2L+2W perimeter), L-shape (main rect + leg, minus shared edge), U-shape (main rect + two legs), or Custom LF for unusual layouts. For Custom, enter the total OPEN perimeter directly (already net of attached sides). L and U-shape inputs accept the secondary leg's length × width independently.

  2. 02

    Set deck dimensions + attached sides

    Length × width in feet. Attached-sides count: 0 = freestanding (full perimeter needs rail), 1 = one side against house (subtract length), 2 = corner-nested (subtract length + width). House-attached sides don't need guardrail per IRC — only the open sides do.

  3. 03

    Enter stair geometry

    Stair count (0-3 landings), total rise (deck height to grade in inches), and total run (stringer horizontal in inches). DeckMath computes the stringer hypotenuse via √(rise² + run²) and adds that length per stair side. Toggle 'handrail both sides' for wider stairs (>44″) per IRC R311.7.8.

  4. 04

    Add gates if any

    Each gate subtracts 3 feet from the guardrail LF (standard residential gate width). Gates are separately costed line items with self-closing + child-safe latch hardware (pool-code compliant). 0-4 gates supported.

  5. 05

    Pick material tier + state

    PT cap ($24/lf, DIY tier 1), composite cap ($42/lf, DIY tier 1 — best value), cable ($58/lf, DIY tier 2 — premium open view), glass ($105/lf, pro-only tier 3 — luxury), aluminum ($48/lf, DIY tier 1 — fastest install). State selection adjusts labor cost via regional multipliers (12 US regions).

How we calculate

The math, fully transparent.

The Railing Linear Feet Calculator sizes the total guardrail + handrail you need for a deck — perimeter minus house-attached sides minus gates, plus the angled stair handrail run, with code-compliant post layout. Pick deck shape (rectangle, L-shape, U-shape, or custom LF), attached-side count, stair geometry, and one of five material tiers: pressure-treated cap rail ($24/lf · DIY), composite cap ($42/lf · best value), cable ($58/lf · open view), glass ($105/lf · luxury), or aluminum picket ($48/lf · low maintenance). DeckMath returns ordering LF including waste, post count at material-specific max spacing (4-6′ o.c. per IRC R312 + manufacturer instructions), the IRC-required guard height (36″ or 42″), and a BoM with installed-cost ranges accounting for regional labor (12 US regions) and permit fees. Distinct from the Baluster Spacing Calculator (D.1, MVP) which fills a known railing length with code-compliant balusters — this calc tells you HOW MUCH RAIL you need before you start measuring balusters.

IRC references

  • IRC 2021 R312.1.1 — Guards required on open sides of decks > 30″ above grade
  • IRC 2021 R312.1.2 — Guard height 36″ minimum (residential); 42″ above 6′ in some jurisdictions
  • IRC 2021 R312.1.3.1 — 4″ sphere rule (no opening allows passage of 4″ sphere through guardrail)
  • IRC 2021 R312.1.3.3 — Stair triangle 4-3/8″ opening limit
  • IRC 2021 R311.7.8.1 — Handrail required on at least one side of stairs with 4+ risers
  • IRC 2021 R311.7.8.3 — Continuous handrail along entire stair flight; returns at top/bottom
  • IRC 2021 R311.7.8.5 — Handrail clearance 1.5″ minimum from wall
  • IRC 2021 R301.5 — Guard live load 50 lb single point applied any direction

Railing pricing 2026-Q1: PT cap $24/lf, composite cap $42/lf (Trex Signature / TimberTech Classic), aluminum picket $48/lf (Westbury / Fortress), cable rail $58/lf (Feeney / Atlantis), tempered glass $105/lf (10mm panel). Labor $12-45/lf by material. Waste 4-10% by material. Post spacing per IRC R312.1.4 + manufacturer.

Rectangle perimeter
P = 2·(L + W)

Sum of all four sides. 16×12 rectangle = 56 LF perimeter. With 1 house-attached side (length = 16′), open perimeter = 40 LF.

L-shape perimeter
P = 2·(L + W) + 2·(L₂ + W₂) − 2·shared

Main rectangle plus leg rectangle, minus twice the shared edge where the leg attaches to the main. For a 16×12 main + 8×6 leg (shared edge = 6′): 56 + 28 − 12 = 72 LF.

Stair handrail hypotenuse
H = √(rise² + run²) / 12

Stringer length per stair. For a 36″ rise + 55″ run stair: √(36² + 55²) / 12 = √(1296 + 3025) / 12 = √4321 / 12 ≈ 5.48 LF per side. Two-side stairs (>44″ wide) double this.

Ordering LF (with waste)
L_order = L_total × (1 + waste%)

Waste varies by material: PT cap 10% (miter cuts + end loss), composite 7%, cable 4% (cut-to-length kits), glass 5%, aluminum 6%. For 40 LF composite cap: 40 × 1.07 = 42.8 LF ordered.

Post count
n = corners + ceil(L_guard / max_spacing) + stair_posts

Cable rail max spacing is 4′ (tension load); composite/PT/aluminum/glass all permit up to 6′. For 40 LF of cable rail in a rectangle: 4 corners + ceil(40/4) − 4 + 1 = 11 posts (guard) + 2 stair posts = 13 total.

IRC guard height
Deck > 30″ above grade → 36″ guard required (R312.1.2)

Residential decks above 30″ must have a 36″ minimum guard. Some jurisdictions require 42″ above ~72″ (commercial threshold). DeckMath flags 42″ when deck height > 72″ as a code-safety hint.

Save your plan

Don’t lose this estimate.

Your inputs are preserved in the URL — email it to yourself or copy the link so you can compare with contractor bids later. No account needed.

Frequently asked

Questions, answered.

Embed this calculator

One line. Any site. Free.

Drop the snippet into your contractor site, blog, or marketing page. Theme matches the parent site automatically.

<!-- Drop into any HTML, WordPress, Webflow, or contractor site -->
<script src="https://embed.deckmath.com/v1.js"
        data-deckmath-calc="railing-linear-feet-calculator"
        data-theme="auto"
        async></script>