What exactly is the relation between these 3 quantities? As far as I can tell the work function is the energy needed to bring an electron from the fermi level out into vacuum, while affinity is from the bottom of the conduction band. Does this then mean that they can be used to calculate the band gap between the conduction band and valence band? For me it would appear so since you normally say that the fermi level is midway between the valence and conduction band. But is this always true, and why is it true?