Introduction
Deck railing looks simple until you start laying out the spindles. The gap between them has to clear code, the spacing needs to look even, and the count has to line up with what you actually buy. Miss any of those and you either fail inspection or end up with a lopsided run.
The code number most US jurisdictions enforce is the 4-inch sphere rule. A 4-inch ball can’t pass through any gap in the guard. Some areas use 3-5/8 inches for commercial work. That’s the maximum gap the calculator aims for.
Post width matters more than people expect. A 4×4 post has a 3-1/2 inch actual width. A 6×6 is 5-1/2 inches. Two posts at each end of a section eat 7 inches or 11 inches from the nominal length before any spindles go in. The calculator subtracts the post width first, then solves for the spindle count that keeps every gap at or under your limit.
It also shows center-to-center spacing, which is the number you mark on the top and bottom rails before you drill. Get that right and the whole run goes together in an afternoon.
How to Use the Spindle Spacing Calculator
Pick your currency from the dropdown if you want the cost in something other than US dollars.
Enter the length of one railing section. This is the full length from outside edge to outside edge of the two end posts.
Enter the width of a single spindle. A standard square baluster runs 1-1/2 inches.
Enter the post width for one post. The calculator doubles it to subtract both ends.
Set the maximum allowed gap. Four inches is the IRC residential limit.
Enter how many sections you’re building.
Choose a spindle profile from the dropdown. It’s recorded for reference but doesn’t change the spacing math.
Enter the price per spindle and the waste factor. Five percent is typical for a straight run.
Add any additional cost, like adhesive or fasteners, as a flat total.
Hit Calculate. The Summary tab shows spindle count, gap, center-to-center spacing, and code status. The Detailed Breakdown tab lists every intermediate value.
How the Spindle Spacing Formula Works
The calculator solves for the number of spindles that keeps every gap at or below the code limit, then checks that the spindles actually fit.
Formula: Clear Opening (in) = Rail Length − (2 × Post Width)
Formula: Spindles per Section = smallest n where [Clear Opening − (n × Spindle Width)] ÷ (n + 1) ≤ Max Gap
Formula: Clear Gap = [Clear Opening − (Spindles × Spindle Width)] ÷ (Spindles + 1)
Formula: Center-to-Center Spacing = Spindle Width + Clear Gap
Formula: Total Spindles with Waste = ceil(Spindles per Section × Sections × (1 + Waste % ÷ 100))
Formula: Total Cost = (Total Spindles with Waste × Price) + Additional
The formula for spindle count works because every section has one more gap than it has spindles. Three spindles create four gaps. Ten spindles create eleven gaps. That extra gap is what fills the space between the outermost spindles and the posts.
The iterative loop starts with one spindle and checks whether the resulting gap is at or under the limit. If the gap is too wide, it adds another spindle and tries again. The first count that works is the answer. Because of that +1 on the gap count, the solution space is tight — you can’t just divide the opening by the max gap and round up. You have to account for the spindle material eating into the opening.
On a 96-inch section with 4×4 posts and 1-1/2 inch spindles, the clear opening is 89 inches. Working through: 18 spindles gives a gap of 3.95 inches. 17 spindles gives 4.42 inches, which fails. So 18 is the answer.
The code compliance line confirms the result. If the gap comes out positive and at or below the limit, the section passes. If you set the max gap too small for the spindle width to work with, the calculator floors at one spindle and reports the best gap it can find.
Worked Example
You’re building a deck rail with two sections. Each section is 118 inches long. The end posts are 6×6 lumber with a 5-1/2 inch actual width. Your spindles are 1-1/2 inch square balusters. Your jurisdiction enforces the 4-inch sphere rule. Spindles cost $7.25 each, waste is 5%, no additional cost.
Step 1: Clear opening.
118 − (2 × 5.5) = 118 − 11 = 107 inches.
Step 2: Try 18 spindles.
Total spindle width = 18 × 1.5 = 27 in.
Remaining space = 107 − 27 = 80 in.
Gaps = 18 + 1 = 19.
Gap size = 80 ÷ 19 = 4.211 in.
That exceeds 4 inches. Try one more.
Step 3: Try 19 spindles.
Total spindle width = 19 × 1.5 = 28.5 in.
Remaining space = 107 − 28.5 = 78.5 in.
Gaps = 19 + 1 = 20.
Gap size = 78.5 ÷ 20 = 3.925 in.
That passes the 4-inch rule.
Step 4: Total spindles for two sections.
19 × 2 = 38 spindles.
Step 5: Add 5% waste.
ceil(38 × 1.05) = ceil(39.9) = 40 spindles.
Step 6: Center-to-center spacing.
1.5 + 3.925 = 5.425 inches.
Step 7: Total cost.
40 × $7.25 = $290.00.
The summary tab reports 107 inches of clear opening, 19 spindles per section, 38 total, 40 with waste, 20 gaps per section, 3.925 inches of clear gap, 5.425 inches center-to-center, code compliant, and $290.00 total cost. The breakdown lists the post subtraction, both spindle-count trials, and every unit conversion.