Here's a fairly straightforward staircase for a loft bed.
I used metal electrical conduit to make the pivot hinge. It's around 20$ in materials.
It's basically a rectangle constructed from conduit that pivots to allow the staircase to extend out. When's in it's closed(folded) position, it stays in place, resting against a couple of wood pieces screwed to the wall.
Notice that the conduit rectangle is screwed to blocks of wood. The blocks are shorter than the conduit rectangle to clear the 90 degree elbows. This allows it to pivot freely.
The steps are at a 30 degree angle and are roughly parallel to floor when the stairs are extended.