To keep your colors matching and avoid return trips to the store, do some calculations ahead of time:

How Much Paint Is Needed for Walls?

Start by adding up the length of all the walls to be painted, from end to end. Then multiply that number (the perimeter) by the height of the walls, from floor to ceiling. That will give you the square footage of the room to be painted. Finally, divide your total number by the approximate coverage of one gallon of paint (about 400 sq. ft. per gal.). This gives you how many gallons of paint you need for one coat of paint on the walls.

More tips on wall paint coverage:

Painting white paint over clean, new white paint? Or same color on top of same color? You might be able to get by with just 1 coat. Porous surfaces like stucco or unpainted drywall absorb paint at a higher rate, so you’ll likely need more paint than the amount calculated. Be prepared for future touch-ups with 1-2 quarts of paint. Get any custom paint at the same time to ensure evenly matched shades.

How Much Paint Is Needed for Ceilings?

As with the walls, to arrive at the ceiling’s square footage, multiply its length by its width. Then, to determine the gallons of paint needed, divide that number by 400.

Excluding Windows and Doors:

If you’re not painting your doors and windows trim, don’t buy paint you won’t need. You can calculate their square footage by multiplying each object’s length x width, then subtract that number from the wall paint total.

Or estimate:

Standard size doors are approximately 20 sq. ft. and windows 15 sq. ft. Add up how many of each are in your project space and subtract that square footage from your wall paint square footage. Divide the new final number by 400 to get your best estimate for how many gallons of paint you’ll need for one coat on the walls and ceiling (minus the doors and windows you’re not painting).

How Much Paint Is Needed for Trim?

A room’s baseboards, windows, doors, and crown molding are often painted in a different finish or color than the walls and ceiling, so you can calculate your trim paint needs separately.

Add up the length of all the trim to be painted, then add up the width of all the trim. (You may need to do this by trim type if they’re not all the same widths.) Multiply length x width to get the square footage of trim to be painted. Divide the total by 400 to get the number of gallons of paint you’ll need for one coat. You’ll likely need less than a gallon for a standard room, so consider buying trim paint in a quart or two.

How Much Primer Do I Need?

Applying primer first helps the paint adhere properly to porous or unpainted surfaces like new drywall, allows for even paint application, and covers up stains. If you’re making a dramatic color switch, a tinted primer in a shade similar to your paint makes coverage easier. (Read more on picking the right primer for your project.)

Primer only covers 200-300 sq. ft. per gallon, so you’ll need slightly more primer than paint. Take your earlier total area and divide that number by 300 to get the minimum gallons of primer you’ll need for one coat.