For most shelves, use nominal 1-inch boards or 3/4-inch plywood with a finished edge. Mount a single shelf on shelf brackets spaced 32 inches apart, with up to 8 inches of overhang at the ends. For heavier loads, like books, space the brackets 16 inches apart.
To mark the bracket positions, tack a chalkline indicating the shelf’s lower edge and pull it taut. True the line with a carpenter’s level and snap it. Screw the brackets to studs; on masonry, use wall anchors.
For a row of shelves, use slotted wall standards with adjustable brackets. Mark the position of the standards’ top edges with a chalkline. After putting the top screw partway into each standard, let it plumb itself by swinging free until it stops. Or check it with a level or plumb line.
To hang a shelf between walls in an alcove or a closet, mark the position of the shelf’s lower edge with a leveled chalkline along the back wall and then along each side. Cut cleats a shelf’s width from ¾ -inch molding or from 1 x 2’s. Nail them into the studs.
On masonry, use cut or masonry nails: predrill holes in the cleats. Add a back cleat for a wide span or a heavy load. Or nail vertical dividers, cut from shelf lumber, between shelves.