Magnitude is a numerical invariant of enriched categories, including in particular metric spaces as $[0,infty)$-enriched categories. We show that in many cases magnitude can be categorified to a homology theory for enriched categories, which we call magnitude homology (in fact, it is a special sort of Hochschild homology), whose graded Euler characteristic is the magnitude. Magnitude homology of metric spaces generalizes the Hepworth--Willerton magnitude homology of graphs, and detects geometric information such as convexity.