Magnitude homology was introduced by Hepworth and Willerton in the case of graphs, and was later extended by Leinster and Shulman to metric spaces and enriched categories. Here we introduce the dual theory, magnitude cohomology, which we equip with the structure of an associative unital graded ring. Our first main result is a recovery theorem showing that the magnitude cohomology ring of a finite metric space completely determines the space itself. The magnitude cohomology ring is non-commutative in general, for example when applied to finite metric spaces, but in some settings it is commutative, for example when applied to ordinary categories. Our second main result explains this situation by proving that the magnitude cohomology ring of an enriched category is graded-commutative whenever the enriching category is cartesian. We end the paper by giving complete computations of magnitude cohomology rings for several large classes of graphs.