Remove the headboard from behind the bed. Lay the headboard on a flat surface with the back facing up toward you.
Measure the height of the headboard from the top edge to the bottom edge and subtract 2 inches. For example, if your headboard is 3 feet high, your number would be 34 inches.
Factor in the height that you want the legs to add to the headboard. For example, if you want the legs to hold the headboard 12 inches off the ground, add 12 inches to 34 inches to get a final number of 46 inches.
Cut two 1-by-4 pieces of lumber to the height you calculated, which is 46 inches in the example. Use a power saw or a hand saw to cut the pieces.
Measure 6 inches in from the left and right edges of the headboard and 2 inches from the top edge. Mark each spot with a pencil.
Place the top of the first 1-by-4 at the mark you made 6 inches in from the right edge. Use a drill to place four wood screws through the leg and into the back of the headboard, spacing the screws 1 to 2 inches apart. Use screws that are short enough to not show through the upholstery.
Place the second 1-by-4 on the mark you made on the left edge. Screw it into place. Stand the headboard upright and return it to its original position.