Wikipedia has a page on sequence logo which discusses the calculation briefly.
The "bits" here are related to those used in Shannon entropy. This is an information-theoretic equivalent to the Boltzmann entropy from thermodynamics. This is a measure of how "disordered" the position is, or more precisely how specific the distribution is.
The general formula for the total entropy (expressed based on probabilities/fractions) is
$$ S = -k \sum_i p_i \cdot log( p_i ) $$
where $i$ ranges across all the various states (e.g. each nucleotide).
The difference between Shannon entropy and Boltzmann entropy (aside from the contexts where it's used) is the value of the constant (one for Shannon, Boltzmann's constant for Boltzmann entropy) and which logarithm used (the natural logarithm for Boltzmann entropy, and typically base-2 for Shannon entropy.) As it uses base-2 logarithms, the Shannon entropy is typically measured in units named "bits".
The wrinkle is that the entropy of a distribution isn't really what you want to display in a sequence logo. Instead, you want something that gets larger (not zero) when the sequence becomes more defined. As such, the values displayed are not the entropy itself, but the "entropy loss" from a completely random (maximal entropy) distribution.
That's how you get the total number of bits at a position (the total height). The height of the individual letters comes by taking the total height and multiplying it by the probability of each state. This might not have rigid theoretical justification (you can't attribute the entropy loss to individual nucleotides like that), but it fulfills the display purposes of making the more prevalent nucleotide identities larger in display size.
For example, if you have a position with 70% G and 30% C, then you have
$$ (4 \cdot -0.25 \cdot log_2(0.25)) - (-0.7 \cdot log_2( 0.7 ) + -0.3 \cdot log_2( 0.3 )) = 1.12$$ bits of total height. G gets a height of $1.12 *0.7 = 0.78$ bits, whereas C gets $1.12 *0.3 = 0.34$ bits.