  Observations of clusters and groups imply that such halos are roughly in
global thermal equilibrium, with heating balancing cooling when averaged over
sufficiently long time- and length-scales; the ICM is, however, very likely to
be locally thermally unstable. Using simple observationally-motivated heating
prescriptions, we show that local thermal instability (TI) can produce a
multi-phase medium---with ~ 10000 K cold filaments condensing out of the hot
ICM---only when the ratio of the TI timescale in the hot plasma (t_{TI}) to the
free-fall timescale (t_{ff}) satisfies t_{TI}/t_{ff} <~ 10. This criterion
quantitatively explains why cold gas and star formation are preferentially
observed in low-entropy clusters and groups. In addition, the interplay among
heating, cooling, and TI reduces the net cooling rate and the mass accretion
rate at small radii by factors of ~ 100 relative to cooling-flow models. This
dramatic reduction is in line with observations. The feedback efficiency
required to prevent a cooling-flow is ~ 0.001 for clusters and decreases for
lower mass halos; supernova heating may be energetically sufficient to balance
cooling in galactic halos. We further argue that the ICM self-adjusts so that
t_{TI}/t_{ff} >~ 10 at all radii. When this criterion is not satisfied, cold
filaments condense out of the hot phase and reduce the density of the ICM.
These cold filaments can power the black hole and/or stellar feedback required
for global thermal balance, which drives t_{TI}/t_{ff} >~ 10. In comparison to
clusters, groups have central cores with lower densities and larger radii. This
can account for the deviations from self-similarity in the X-ray
luminosity-temperature (L_X-T_X) relation. The high-velocity clouds observed in
the Galactic halo can also be due to local TI producing multi-phase gas close
to the virial radius.
