The origin of the extragalactic gamma-ray background (EGRB) is an important open issue in the gamma-ray astronomy. There are many theories about the origin of EGRB: (1) some truly diffuse processes, such as dark matter (DM) annihilation or decay, which can produce gamma rays; (2) gamma rays produced by energetic particles accelerated through induced shock waves during structure formation of the universe; (3) a lot of unidentified sources, including normal galaxies, starbursts and active galactic nuclei (AGNs), contain a large number of energetic particles and can emit gamma rays. Among various extragalactic sources, blazars including flat spectral radio quasars (FSRQs) and BL Lac objects are one of the most possible sources for EGRB. As continuous accumulation of the data observed by the Fermi Gamma-Ray Space Telescope, it is possible to directly construct gamma-ray luminosity function (GLF) of the blazars involving evolution information. In this chapter, based on the largest clean sample of AGNs provided by Fermi Large Area Telescope (LAT), we mainly study blazar's GLFs and their contribution to EGRB. In our study, we separately construct GLFs of FSRQs and BL Lacs and then estimate the contributions to EGRB, respectively. Further, we discuss the diffuse gamma ray from other astrophysical sources and the other possible origins of the EGRB.