text: The most commonly known solar cell is configured as a large-area p-n junction made from silicon. As a simplification, one can imagine bringing a layer of n-type silicon into direct contact with a layer of p-type silicon. n-type doping produces mobile electrons (leaving behind positively charged donors) while p-type doping produces mobile holes (and negatively charged acceptors) In practice, p-n junctions of silicon solar cells are not made in this way, but rather by diffusing an n-type dopant into one side of a p-type wafer (or vice versa).
  If a piece of p-type silicon is placed in close contact with a piece of n-type silicon, then a diffusion of electrons occurs from the region of high electron concentration (the n-type side of the junction) into the region of low electron concentration (p-type side of the junction). When the electrons diffuse into the p-type side, each one annihilates a hole, making that side net negatively charged (because now the number of mobile positive holes is now less than the number of negative acceptors). Similarly, holes diffusing to the n-type side make it more positively charged. However (in the absence of an external circuit) this diffusion current of carriers does not go on indefinitely because the charge build up on either side of the junction produces an electric field that opposes further diffusion of more charges. Eventually, an equilibrium is reached where the net current is zero, leaving a region either side of the junction where electrons and holes have diffused across the junction and annihilated each other called the depletion region because it contains practically no mobile charge carriers. It is also known as the space charge region, although space charge extends a bit further in both directions than the depletion region.
  Once equilibrium is established, electron-hole pairs generated in the depletion region are separated by the electric field, with the electron attracted to the positive n-type side and holes to the negative p-type side, reducing the charge (and the electric field) built up by the diffusion just described. If the device is unconnected (or the external load is very high) then diffusion current would eventually restore the equilibrium charge by bringing the electron and hole back across the junction, but if the load connected is small enough, the electrons prefer to go around the external circuit in their attempt to restore equilibrium, doing useful work on the way.