Insulation is part of the whole roof system and designed to prevent both cold and heat from entering the house. Insulation is rated by R factors, a measurement of resistance to heat flow. Heat is energy and always moves toward cooler areas: out of the house in winter, into the house in summer.
The temperature in a well-ventilated attic ideally should only be a few degrees different than the outside temperature. Therefore to protect the house, the first place to install insulation in an attic is between ceiling joists. If using batts, place the paper or vapor retarder side, against the ceiling to resist the movement of water vapor. If using loose fill, a vapor retarder ideally should have been placed over the bottom of the ceiling joists before the drywall was installed.
Ideally an attic should have a gap-free layer of insulation on the attic floor to protect the house below from heat gain or loss. It should also have a vapor retardant under the insulation and next to the ceiling to stop moisture from rising into the attic.
Be sure that insulation between ceiling joists does not block any soffit vents. If your house has them, keep the insulation about a foot short of the connection between roof and wall to permit free air movement.
If it’s in your budget, you can also place insulation batts between the roof rafters and the walls, but that will have considerably less impact on protecting the house than putting insulation between ceiling joists.
If you have a cathedral ceiling with little room for standard insulation without blocking air movement, then use baffles to create a space between the roof deck and the insulation. If your cathedral ceiling is formed by tongue and groove lumber on top of rafter beams, you can also use rigid insulation on top of the roof deck, under the roof covering.