PN Junction
#Electronics
Now let’s put a P-type and an N-type semi-conductor next to each other (the P-type part to the left and the N-type to the right).
Because both the P-type and the N-type semi-conductor have zero net charge, there will be no electric field present. What happens next is called diffusion. Basically, because there is a place dense with negative charge, this negative charge tends to spread until the density of charge is equal everywhere. The same happens with the positive charges (the holes). This diffusion process is similar to what we see with cigar smoke in a room (example from Dr. Sharif Bakhtiar’s Electronics 2 course at Sharif University of Technology). The smoker does not blow intentionally and there is no wind, yet the smoke spreads in the room.
As a result of the diffusion process, the free electrons go from the N-type to the P-type junction (from right to left) and there they fill the holes. Therefore, after some time, a depletion region will be created in the middle, between the two junctions. This depletion region contains fixed-in-place positive charges in the N-type side (right side) and fixed-in-place negative charges in the P-type side (left side). This forms an electric field, pointing from the N-type (right) to the P-type (left) side. This electric field resists the movements caused by the diffusion. Therefore, after a while, the system reaches an equilibrium. In this state, diffusion wants to move electrons to the P-type side, but the electric field (the drift current) resists.

Continue learning about electronics here.