Diffusion and Drift are the two processes that take place in the formation of a p-n junction.
In an n-type semiconductor, the concentration of electrons (number of electrons per unit volume) is more compared to the concentration of holes. Similarly, in a P -type semiconductor, the concentration of holes is more than the concentration of electrons. During the formation of p-n junction.
Due to the diffusion of electrons and holes across the junction a region of
(immobile) positive charge is created on the n-side and a region of(immobile) negative charge is created on the p-side, near the junction; this is called depletion region.
Barrier potential is formed due to loss of electrons from n-region and gain of electrons by p-region. Its polarity is such that it opposes the movement of charge carriers across the junction.