In a p-n junction, when p-type and n-type materials are brought together, electrons from the n-type region diffuse into the p-type region and combine with holes, while holes from the p-type region diffuse into the n-type region and combine with electrons. This diffusion process creates a region devoid of free charge carriers, known as the depletion region. The remaining immobile ions in this region create an electric field that opposes further diffusion, thus establishing an equilibrium.