As a low refractive index material widely used in coatings for deep-ultraviolet optical systems, magnesium fluoride (MgF2) films were prepared by electron beam evaporation at different substrate temperatures. The effects of the substrate temperatures on the optical properties in vacuum and in air, microstructures, and composition were investigated, as were the microstructures, their composition, and the relation between them. In vacuum, the substrate temperature directly affected the microstructures which dominated the packing density and inhomogeneity along the film thickness. When the films were exposed to air, the refractive index increased and a nonmonotonic change trend of the refractive index with substrate temperature was observed due to adsorbed water and magnesium oxide (MgO) formed in the film. While a moderate amount of MgO reduced absorption loss by decreasing vacancy defects, excessive MgO increased the absorption loss because of the high extinction coefficient of the oxide.