Worked example
A 24 foot straight rail with posts at most 6 feet apart is four sections of 6 feet. Each 72 inch section, with 1 1/2 inch balusters and a 4 inch maximum opening, needs 13 balusters. The opening is 3.75 inches. Four sections are 52 balusters. At 10% waste you buy 58. Posts: 5, because a straight run has a post at each end.
The formula
n balusters and n + 1 openings fill the section. If every opening must be at most G and each baluster is W wide, then n is (section − G) ÷ (W + G), rounded up. The page then reports the real opening after that round-up, which is a little tighter than G.
An 8 foot section under the same defaults needs 17 balusters, not 13. Longer bays are not a free stretch of the same spacing. See joist spacing for the same kind of “both ends count” idea on the frame, and the board calculator for the decking those joists carry.
Common questions
How many balusters are in an 8 foot section?
With 1 1/2 inch balusters and a maximum opening of 4 inches, an 8 foot (96 inch) section needs 17 balusters. The opening works out to about 3.92 inches, which is under 4. A 6 foot section needs 13, with a 3.75 inch opening. Your local rule may not be 4 inches. Type the opening you were told to meet.
Why are there openings at the posts?
The count assumes a gap at each end post as well as between balusters. n balusters create n + 1 openings. If you tighten the balusters against the posts and only gap between them, you need a different layout. Do not leave an end gap larger than the opening you set.
How do posts work on a closed deck?
A straight run has a post at both ends, so posts equal sections plus one. A closed pen shares every corner. Check closed loop and the post count equals the number of sections. Enter the perimeter once. Do not add four separate sides and then add their end posts, or each corner is ordered twice.