Underlayment is installed beneath the outer roofing material (shingles or metal panels) and directly on top of the roof deck. Its primary purpose is to provide an extra layer of protection against water infiltration and to enhance the overall weather resistance of the roof.