TeX calculates badness of boxes wider than their implicit width but also of boxes narrower than their implicit width. There is symmetry from this point of view. The spaces include their implicit width and their stretch value and shrink value (i.e. there are three values for each space). When a box should be stretched from its implicit width then the sum of all stretching values from present spaces are counted. When the box should be narrowed then all shrinking values are counted. In both cases, denote this sum S.
Denote the required stretching or shrinking R. Then the badness is calculated as 100*(R/S)^3.
The only difference (or asymmetry) between stretching and shrinking is that TeX allows boxes wider than S, i.e. R should be greater than S, i.e. badness should be greater than 100. But this isn't allowed for shrinking. The S is maximum allowed shrinking, never more. If the R>S in case of shrinking then the box is set as if R=S and the rest of box material exceeds over the box boundary to the right. This specific case is Overfull \hbox and the badness is assumed infinity (not calculated). The amount of exceeding over the box is reported.
When stretching box and R>S, then badness is calculated and spaces inside this box are stretched wider than their stretch value. The badness value has its allowed maximum 10000 and if the formula for badness (mentioned above) gives higher value then badness is set to 10000.
Assume the following example. The warning reports are added as a comment to appropriate line in this example:
\hbadness=0
\hbox to20pt{a b} % Underfull \hbox (badness 4927) detected at line 3
\hbox to18pt{a b} % Underfull \hbox (badness 1496) detected at line 4
\hbox to16pt{a b} % Underfull \hbox (badness 203) detected at line 5
\hbox to15pt{a b} % Loose \hbox (badness 29) detected at line 6
\hbox to14pt{a b}
\hbox to13pt{a b} % Tight \hbox (badness 51) detected at line 8
\hbox to12pt{a b} % Overfull \hbox (0.7778pt too wide) detected at line 9
\setbox0=\hbox{a b}
normal width: \the\wd0 % 13.88892pt
stretch value: \the\fontdimen3\font % 1.66666pt
shrink value: \the\fontdimen4\font % 1.11111pt
\bye
We want to print warnings for all positive badness values. This is done using \hbadness=0
. We try to calculate the badness manually, for example for the line 5:
The implicit width of the box is 13.88892pt, the box should be 16pt width, i.e. 2.11108pt wider than its implicit width. This is R value and we want to stretch the box. The stretching value of the space in the box is 1.66666pt, this is S value. Badness is 100*(2.11108/1.66666)^3 = 203.223. Badness is an integer value, i.e. 203.
Note that the line 6 reports "Loose" box (i.e. the box wider than its implicit width but with R<S). The line 6 reports "Tight" box, i.e. the box narrower than its implicit width but not overfull. The badness calculation for this line is b = 100*(.88892/1.11111)^3 = 52. The shrink value 1.1111pt of the space is used here.
Note that the line 7 reports no warning, because badness is
100*(.11108/1.6666)^3 = .029 = 0.