We report first-principles microscopic calculations of the formation energy, electrical activity, and magnetic moment of Co dopants and a variety of native defects in TiO2 anatase. Using these results, we use equilibrium thermodynamics to predict the resulting carrier concentration, the average magnetic moment per Co, and the dominant oxidation state of Co. The predicted values are in good agreement with experiment under the assumption of O-poor growth conditions. In this regime, a substantial fraction of Co dopants occupy interstitial sites as donors. The incomplete compensation of these donors by substitutional Co acceptors then leads to n-type behavior, as observed experimentally.