Doping introduces impurities into a semiconductor crystal to modify its conductivity. N-type doping uses elements with 5 valence electrons like phosphorus, which provides an extra electron that is loosely bound and can move freely. P-type doping uses elements with 3 valence electrons like boron, which accepts an electron from the semiconductor, leaving behind a positively charged hole. Both doping types increase the number of charge carriers, with n-type providing free electrons and p-type providing free holes. This allows control over whether the semiconductor behaves as an electron or hole conductor.