We formulate a version of the integral Hodge conjecture for categories, prove the conjecture for two-dimensional Calabi–Yau categories which are suitably deformation equivalent to the derived category of a K3 or abelian surface, and use this to deduce cases of the usual integral Hodge conjecture for varieties. Along the way, we prove a version of the variational integral Hodge conjecture for families of two-dimensional Calabi–Yau categories, as well as a general smoothness result for relative moduli spaces of objects in such families. Our machinery also has applications to the structure of intermediate Jacobians, such as a criterion in terms of derived categories for when they split as a sum of Jacobians of curves.