Why decks drink more stain than you expect
The maths is simple: deck area is length × width, railing area is roughly 2 sq ft for every linear foot of railing (that allowance covers the top rail, the bottom rail, the posts and both faces of the balusters), and the two added together are multiplied by the number of coats and divided by the coverage per gallon. What trips people up is the coverage figure. A can that claims 250–350 sq ft per gallon is quoting a smooth, sealed, planed surface. A deck is none of those things. Horizontal boards are exposed to sun and rain, the grain opens up, and the end grain and the gaps between boards pull stain in like a wick. On bare, weathered or rough-sawn lumber it is common to get well under half the label figure on the first coat, then close to the label figure on the second — which is why staining is best treated as "first coat unpredictable, second coat predictable."
A few practical points before you buy. Semi-transparent and clear products penetrate and use more; solid-colour stains sit closer to the surface and stretch further, but they will need stripping rather than a simple re-coat later on. Never apply a second coat to a deck that has stopped absorbing — surplus stain that cannot soak in stays sticky and peels within a season, so the "how many gallons" answer is a ceiling, not a target. Buy all your gallons in one purchase and box them (pour them together into a larger pail and mix) so that colour is consistent across the whole deck. Finally, add the stairs: a flight of stairs adds tread, riser and stringer surface that is easy to forget, so add its tread area into the deck length × width figure. Aim to have a partial can left over rather than running out three boards from the end.
Coverage varies widely by product, wood species, age and surface porosity — always check the coverage stated on the label and treat this figure as a planning estimate only.