Have an assistant hold a 1-by-26-by-26-inch plywood board in place and set a 2-by-2-by-24-inch posts underneath it, directly in one of the corners. Position a 2-inch hinge between the post and the board so that, once installed, the post will fold back onto the plywood board, near the edge of the board.
Drill the mounting holes in both the post and the plywood board, based on the holes in the hinge. Use 3/4-inch wood screws to mount the hinge to the post and the board.
Repeat the process with another 2-by-2-by-24-inch board on an adjacent corner, so that both posts fold back in a parallel manner near their side of the board.
Mark the location of the studs in the wall if applicable using the stud finder. Fold down these legs and position the table against the wall in the desired location. Adjust the positioning so the legs are on the floor and then have an assistant hold the table in place.
Set an 18-inch piano hinge between the wall and the table board. Mark the location of screw holes every 2 inches or so in the table. Line up the piano hinge screw holes with the stud locations and mark them, or just pick three evenly space spots and insert drywall anchors in each spot.
Drill into the table and wall to make holes in all the markings. Attach the hinge to the table with 3/4-inch wood screws and to the wall with 3-inch wood screws.