Position two 3/4-by-12-by-12-inch plywood boards parallel to each other on their long, thin sides. Space them 40 inches apart and consider them the side boards.
Set a 3/4-by-12-by-40-inch plywood board, which is the top board, against the ends of these side boards so the boards make a U. Set 1-inch metal L-brackets between the side boards and the top board. Mark the holes in the brackets. Drill out each hole. Attach the brackets with 3/4-inch wood screws.
Determine and mark the location of the wall studs in the installation area. Position the U-shaped frame against the wall so that at least one of the side boards lines up with a stud. Position metal brackets within the frame against the wall wherever the wall studs are, spaced every six inches. Mark the screw holes, drill them out and attach the brackets to the wall with 2 1/2-inch wood screws. Attach the brackets to the frame with 3/4-inch wood screws.
Set out two 80-inch 2-by-4 boards on one of their large surfaces, parallel to each other about 40 inches apart. Position 12 evenly spaced 40-inch 2-by-4 boards perpendicularly across the long boards with their large surfaces facing down.
Drill two holes through each short board and into each long board for a total of 48 holes. Attach the boards together by drilling 2 1/2-inch wood screws through each hole.
Set the bed frame on top of four 3 1/2-by-3 1/2-by-9-inch wood posts, with the wood posts in each corner of the bed frame, flush with the outside edges. Drill two holes down through the top of each corner and into each wood post. Secure the posts in place with 5-inch wood screws drilled through the holes.
Position the head of the bed against the headboard. Set a piano hinge evenly along the top of both the headboard and the bed frame. Mark piano hinge screw attachment holes every three inches in both surfaces. Remove the hinge and drill out the marked holes. Replace the hinge and attach it in place with 2 1/2-inch wood screws in the bed frame and 3/4-inch screws in the headboard.
Fold up the bed frame and have an assistant hold it against the wall. Separate a 60-inch nylon strap with a buckle into its component pieces. Staple the two halves to the underside of the bed frame, opposite each other about three inches from the outside edge of each side of the bed and two feet from the foot of the bed, so that they can be buckled on the top of the bed and hold the mattress in place. Attach a second strap about two feet from the head of the bed.
Find two positions within wood screws on either side of the bed, about halfway up the bed when it is folded upright. Drill out the two positions and attach 1-inch diameter eyebolts in the holes. Clip a 1-inch carabiner to the eyehooks and attach a chain to both carabiners, tightening as necessary to keep the bed tight against the wall.