"One post every eight feet" is where most fence estimates start, and where they go wrong: a 20 ft run is not 2.5 bays, and a gate takes two extra posts. The new fence calculator in the wall-framing-takeoff project cuts each run, less its gates, into the fewest equal bays no wider than your post spacing, so every rail ends on a post.
For 40, 20 and 40 ft runs with one 48 in gate and a 6 ft privacy fence it counts 16 posts (4 end and corner, 10 line, 2 gate), 14 bays, 42 rails of 8 ft at three per bay, 222 pickets with 5% waste, 31 bags of 80 lb concrete for 10 in holes 30 in deep, and 1,332 fasteners. A 6 ft fence with 30 in buried needs a 10 ft post. It also flags fences over 6 ft (permits) and posts buried under a third of their height.
Every default is a typed figure, not a code's: enter your own frost depth, spacing and picket size. No real fence plan has been run through it, and gate frames, slope and bracing are not counted. It runs in your browser: ventures/wall-framing-takeoff/fence-calculator.html, MIT licensed.