Remove the shingles or other roofing materials. Strip the roof down to its basic decking, usually plywood or oriented strand board. Inspect the decking and replace any that is damp, rotted or otherwise damaged. Cut new decking to fit if necessary with a circular saw and fasten it with galvanized shingle nails and a hammer. Drive in any protruding nails.
Choose a type of foam board, expanded polystyrene, extruded polystyrene or polyisocyanurate. Use polyiso for a thin board; it has the highest R value, up to R 8 per inch, but is most expensive. Pick ESP for economy; it is cheapest but with the lowest R value, about R 4 per inch. Install XPS, the extruded version, for the best compromise; it has an R value of about R 5 per inch and high compressive strength so it does not bend or dent easily on a roof.
Place foam panels so the seams do not align with the joints on the roof decking panels. Lay panels with the vapor barrier side down on the decking; most rigid foam board roof insulation has some type of facing on one side as a moisture barrier. Fasten panels with galvanized roofing nails driven through the sheathing into the truss rafters. Don't pound nails deeply into the foam board.
Cover the foam board joints and nail heads with tape. Use a type to match the type of foam board, from the same manufacturer. Put tape across all seams and over the peak where two foam panels meet. Overlap those panels so the edge of one covers the top edge of the abutting panel on the other roof slope.