  Combining Varadhan's formula, Loewner's theorem with the method of stationary
phase, we study the exact formula of the Carnot-Carath\'eodory distance on
$2$-step groups. The method is also adapted to determine all normal geodesics
from the identity element to any given point (up to a set of measure zero). As
an application, we characterize the squared sub-Riemannian distance as well as
the cut locus on generalized Heisenberg-type groups and on star graphs
respectively. Furthermore, the long-standing open problem of Gaveau-Brockett is
completely solved in the case of $N_{3, 2}$, the free Carnot group of step two
and 3 generators.
