How does wearing a hat keep you warm (or cool)?
First, a hat serves as insulation against convective heat transfer. By trapping a layer of air near your skin, it slows the movement of air and heat away from your head. But it also acts as a barrier to thermal radiation. Just as a tree overhead radiates heat toward your skin and keeps you from losing heat to the dark night sky, the hat on your head radiates heat toward you and helps to keep you warm. On a sunny day, it keeps you cool by blocking the direct transfer of heat from the sun to your head.