Prepare the mantel to be mounted. Sand away any rough spots with medium-grit sandpaper. Prime and stain the mantel as you desire before you install it, since this is much more difficult to do afterward.
Spread out a tarp on the floor. Turn the mantel upside down and rest the surface of the shelf on the tarp against the floor. Attach the legs to the mantel shelf, fitting the pegs and the holes together with a wiggling motion to ensure a secure fit; turn the screws right one-quarter turn to hold the legs in place.
Move the mantel to the fireplace where it will be installed. Set the mantel into place, center it, and rest it against the wall. Lay a construction level onto the mantel shelf and check to make sure it is straight in both directions; use shims under the legs of the mantel if necessary to level it.
Trace around the outside of the mantel onto the wall with a pencil. Lay the mantel face-down on the tarp on the floor. Stretch a tape measure across the inside of the mantel shelf and write down the measurement.
With a table saw, cut a 2-by-4 board to the length of the measurement from the previous step. Lay the board in the center of the inside of the shelf to make sure it is right. Measure from the top of each mantel leg to the bottom and cut boards to these lengths; lay them vertically in the center of each leg back to check their size.
Use the tape measure to check the width thickness of the back trim of the mantel at the shelf and each leg. Write down these measurements with the pencil inside of the outline you made earlier on the wall, so that you know how much allowance you need. Mark with the pencil where to hang the 2-by-4s you cut earlier, called cleats, based on your drawing.
Position the cleat that goes behind the shelf in place against the wall. Bore four half-inch pilot holes evenly across the surface of the cleat and into the surface behind it. Install a 2-½ inch concrete screw into each hole.
Attach each of the leg cleats to the wall as you did the shelf cleat. Lift the mantel and line up the edges with the pencil sketch on the wall. Slide the mantel into place over the cleats and push it snugly against the wall.
Sink 2-inch finishing screws down through the back edge of the shelf and into the cleat beneath it in a straight line; space each screw about 16 inches apart. Make similar lines of screws down the inside edge (the edge against the wall) of each leg and into its corresponding cleat.
Install thin strips of edge molding along the gaps in the inner perimeter of the mantel with 4d finishing nails. Cover the screw heads with carpentry plugs. If you don't mind painting the mantel one last time after hanging it, you can fill the holes with wood putty instead.