free electronholeSilicon doped with phosphorus has spare electrons (n-type), and silicon doped with boron has holes where electrons are missing (p-type). Where the two meet, electrons fill the nearby holes and leave a thin zone with no free carriers at all, which blocks current. Connect the battery forward and it pushes both kinds of carrier into the junction, the zone shrinks away, and electrons and holes meet and cancel, so current flows. Reverse it and the battery pulls carriers away, the zone widens, and almost nothing flows. That one-way valve is a diode.