How the paint math works
Wall area is the room's perimeter times the wall height: 2 × (length + width) × height. From that you subtract the openings you won't paint — the standard estimating allowances are 21 sq ft per door and 15 sq ft per window — then multiply by the number of coats, because a second coat is a second full pass over every square foot. Divide by coverage (350 sq ft per gallon is the standard planning figure) and round up to the nearest quart, since that's the smallest can worth buying.
The formula
gallons = area ÷ 350, rounded up to the next quart
L, W, and H are in feet. The ceiling, if you're painting it, adds the floor area (L × W) per coat — though note that ceilings are usually done in flat ceiling paint, so treat that as a separate can, not extra wall color.
Worked example
A 12 × 15 ft bedroom with 8 ft walls, 2 doors, and 2 windows: walls are 2 × (12 + 15) × 8 = 432 sq ft, minus 42 (doors) and 30 (windows) = 360 sq ft per coat.
Two coats makes 720 sq ft of painting. At 350 sq ft per gallon that's 720 ÷ 350 = 2.06 gallons — rounded up to the next quart, buy 2 gallons + 1 quart. (Since a quart often costs nearly half a gallon's price, many painters just buy 3 gallons and keep the extra for touch-ups.)
Why two coats, and why coverage is a range
Two coats is the default for a reason: a single coat almost never hides evenly. The old color ghosts through, roller overlap shows as stripes in raking light, and future touch-ups "flash" against single-coat walls. The 350 sq ft/gallon figure is honest but slippery — rough texture, bare drywall, and porous surfaces drink paint and can pull real coverage down toward 250, while smooth previously-painted walls stretch past 400. And when you buy, err slightly high on purpose: paint colors are mixed per batch, and a can tinted next month may not match today's walls exactly. The leftover quart from the original batch is the only touch-up paint that's guaranteed to match.