  Characterizing the conversion factor between CO emission and column density
of molecular hydrogen, X_CO, is crucial in studying the gaseous content of
galaxies, its evolution, and relation to star formation. In most cases the
conversion factor is assumed to be close to that of giant molecular clouds
(GMCs) in the Milky Way, except possibly for mergers and star-bursting
galaxies. However, there are physical grounds to expect that it should also
depend on the gas metallicity, surface density, and strength of the
interstellar radiation field. The XCO factor may also depend on the scale on
which CO emission is averaged due to effects of limited resolution. We study
the dependence of X_CO on gas properties and averaging scale using a model that
is based on a combination of results of sub-pc scale magneto-hydrodynamic
simulations and on the gas distribution from self-consistent cosmological
simulations of galaxy formation. Our model predicts a value of X_CO that is
consistent with the Galactic value for interstellar medium conditions typical
for the Milky Way. For such conditions the predicted X_CO varies by only a
factor of two for gas surfaced densities in the range \sim 50 - 500 M_sun /
pc^2. However, the model also predicts that more generally on the scale of
GMCs, X_CO is a strong function of metallicity, and depends on the column
density and the interstellar UV flux. We show explicitly that neglecting these
dependencies in observational estimates can strongly bias the inferred
distribution of H2 column densities of molecular clouds to have a narrower and
offset range compared to the true distribution. We find that when averaged on
\sim kpc scales the X-factor depends only weakly on radiation field and column
density, but is still a strong function of metallicity. The predicted
metallicity dependence can be approximated as X_CO \sim Z^{-{\gamma}} with
{\gamma} ~ 0.5 - 0.8.
