Gallons = net area × coats ÷ coverage, then waste.
Gross wall area is the perimeter times the height: 2 × (length + width) × height. Subtract doors and windows. Multiply by coats, divide by the coverage per gallon, and add a waste percent for color changes, texture, and the bottom of the can. The default coverage is 350 square feet per gallon per coat, a common label range, not a promise. Porous drywall and a deep color often cover less. Ceilings and trim are separate areas. Add them as their own run or include them in the openings math only if you mean to.