Cut a 2-by-2 board so that you have two 40-inch-long pieces. Cut three support beams, or braces, of 2-by-2 lumber with 45-degree angled ends, using a miter saw. The outside length of the braces needs to be 14.1 inches. Cut a 1-by-12 wood plank to 40 inches long.
Attach one of the 2-by-2s to the bottom of the 1-by-12. The beam should sit flush with the front edge of the wood plank. Drill 2-inch wood screws through the top of the plank into the 2-by-2 every 6 to 8 inches along the length of the board, to create a lip beneath the shelf.
Trace the location of studs in the wall with a stud finder. Mark the location of three consecutive studs with a pencil. Draw a straight line, making it even with a level, from the first stud to the third stud at the height at which the shelf needs to sit.
Press the second 40-inch 2-by-2 against the wall so that the board is flush with the line drawn in Step 3 and crosses each of the three wall studs. Center the middle stud on the 2-by-2. Drill a 4-inch anchor screw through the 2-by-2 into the center stud. Set the level on top of the beam to ensure the beam is kept level. Drill anchor screws through the beam into the left and right studs.
Place the 1-by-12 on top of the 2-by-2 attached to the wall. Face the plank so that the lip installed in Step 2 is on the bottom of the side away from the wall. Drive 2-inch wood screws every 6 to 8 inches down through the 1-by-12 into the 2-by-2 attached to the wall.
Place one of the angled 2-by-2s at the center stud so that one angled end is flush with the wall and the other angled end is flush with the underside of the shelf. That end needs to rest against the back of the lip on the bottom of the shelf. Drill a 3-inch wood screw through the base of the beam into the wall stud. Drill a 2-inch wood screw through the top of the shelf into the 2-by-2 at an angle equal to the angle of the 2-by-2. Countersink the screw so that the head sits below the surface of the wood. Repeat this with the other two 2-by-2s and wall studs, so that there are three braces along the underside of the shelf.