The depletion region in a p-n junction is formed by the diffusion of charge carriers, which leaves behind immobile positive ions on the n-side and negative ions on the p-side. This separation of fixed charges creates the potential barrier.