  We investigate the maximum cardinality and the mathematical structure of
error-correcting codes endowed with the Kendall-$\tau$ metric. We establish an
averaging bound for the cardinality of a code with prescribed minimum distance,
discuss its sharpness, and characterize codes attaining it. This leads to
introducing the family of $t$-balanced codes in the Kendall-$\tau$ metric. The
results are based on novel arguments that shed new light on the structure of
the Kendall-$\tau$ metric space.
