  Compact elliptical (cE) galaxies remain an elusively difficult galaxy class
to study. Recent observations have suggested that isolated and host-associated
cEs have different formation pathways, while simulation studies have also shown
different pathways can lead to a cE galaxy. However a solid link has not been
established, and the relative contributions of each pathway in a cosmological
context remains unknown. Here we combine a spatially-resolved observational
sample of cEs taken from the SAMI galaxy survey with a matched sample of
galaxies within the IllustrisTNG cosmological simulation to establish an
overall picture of how these galaxies form. The observed cEs located near a
host galaxy appear redder, smaller and older than isolated cEs, supporting
previous evidence for multiple formation pathways. Tracing the simulated cEs
back through time, we find two main formation pathways; 32 $\pm$ 5 percent
formed via the stripping of a spiral galaxy by a larger host galaxy, while 68
$\pm$ 4 percent formed through a gradual build-up of stellar mass in isolated
environments. We confirm that cEs in different environments do indeed form via
different pathways, with all isolated cEs in our sample having formed via
in-situ formation (i.e. none were ejected from a previous host), and 77 $\pm$ 6
percent of host-associated cEs having formed via tidal stripping. Separating
them by their formation pathway, we are able to reproduce the observed
differences between isolated and host-associated cEs, showing that these
differences can be fully explained by the different formation pathways
dominating in each environment.
