I wanted to build a table for my brother's treehouse that could collapse and not take up space when he wasn't using it. This is what I ended up with.
Step 1: Materials
Some 2x4s and plywood.
Also, if you don't already have them, some hinges and metal latches.
Step 2: Design
Obviously, the design is circumstantial based on your parameters, and I changed a few things along the way to make it work, but this is the basic idea. (Blame Paint).
Step 3: Build
So basically, it's a 2x4 frame covered in plywood. The legs are just 2x4s that hinge at the bottom front so they fold underneath, and the top of the table hinges to a small part (also 2x4 covered with plywood) which is the part that you attach to the wall.
Step 4: Install
Put it wherever you want. Use a bolt, or screws to attach the top part to the wall. As I mentioned, I put it in my brothers treehouse, but a different size would work for a workshop or whatever else. Also, I added a latch so it wouldn't fall open on it's own.
I hope this inspires someone to try something similar. Thanks for reading.