Measure the distance between the outside edges of two parallel ceiling rafters. Depending on how wide you want your shelf to be, you can use adjacent rafters or rafters that are separated by one or more intervening rafters. Cut two 2-by-4 boards to match the distance measured.
Cut four 2-by-4 boards to 24 inches in length. Place two of the boards against the ceiling rafters at the spot where you want the front edge of the shelf to go, extended downward vertically. Overlap the ends of the boards onto the ceiling rafters by 2 inches then screw the boards to the rafters with two wood screws.
Place the other two boards at the back edge of the planned shelf location. Overlap the ends of the boards as in Step 2 and screw them into place with wood screws.
Position the first two boards you cut onto the bottom edges of the vertical boards, positioned horizontally to connect the two boards. Screw the boards together with two wood screws at each junction.
Cut a sheet of plywood to match the width and depth of the area bounded by the vertical and horizontal boards. Slide the plywood onto the boards and nail it in place with 8d nails.