This is a very good question.
Fermi level for electrons (in n-type semiconductor) and for holes (in p-type semiconductor) are different. When n-type and p-type semiconductors are making a contact (to form a p-n junction), Fermi levels should become equal - that's the requirement for zero current flow (in steady-state or equilibrium condition, there should be no current). Equilibration of the Fermi levels is achieved by charging of the p- and n-type semiconductors - p-type is charged negatively, and n-type - positively. Thus, there is a potential difference between n- and p-type regions even when applied voltage V=0. The potential difference occurs in the depletion region around the metallurgical p-n junctions. The depletion region is where the charging of the semiconductors occur - and the charges are due to the ionized impurities not neutralized by the mobile carriers charges. The rest of the semiconductor (outside the depletion region) is electrically neutral.
The magnitude of the so-called built-in voltage (potential difference between n- and p-type regions) of the p-n junction is:
Vbi=kT/e*ln(NP/ni^2),
where kT/e is thermal potential (~25.8 mV at T=300K), N and P are doping density in n- and p-type regions, and ni is the intrinsic carrier concentration (~1e10 cm-3) at room temperature in Si).
Vbi is close to the bandgap (divided by electron charge e) - i.e ~1.1V in Si.
When external voltage V is applied to p-n junction (forward or reverse), it is added in addition to the buil-in voltage, so that the total potential difference between n- and p-type regions becomes: Vbi+V.