\(A \mapsto \Spec A\) is an anti-equivalence from rings to affine schemes. More generally, for any scheme \(X\) and any ring \(A\), \[ \Hom_{\mathsf{Sch}}(X, \Spec A) \cong \Hom_{\mathsf{Ring}}(A, \OO_X(X)) . \]
(Affine varieties)
Over an algebraically closed field \(k\), \(X \mapsto A(X)\) is an anti-equivalence from affine varieties over \(k\) to finitely generated \(k\)-algebras that are domains. [@Har10a]
A scheme \(X\) is affine exactly when the canonical morphism \(X \to \Spec \OO_X(X)\) is an isomorphism.
The adjunction is the practical test, and it is why the question “how can you tell if a scheme is affine” has a first answer that needs no cohomology: compute the global sections, and compare \(X\) with the spectrum of that ring.
Doing this on \(\PP^1_k\) gives \(\OO(\PP^1) = k\) and \(\Spec k\) a point, so the comparison map collapses the line and \(\PP^1\) is not affine. Doing it on \(\AA^2 \sm \ts{0}\) gives \(\OO(\AA^2 \sm 0) = k[x,y]\) by Hartogs, and the comparison map is the inclusion into \(\AA^2\), which is not an isomorphism: the standard example of a non-affine scheme whose ring of functions is nevertheless that of an affine.
The cohomological criterion — \(H^1\) vanishing against all quasicoherent sheaves — is the version that is a criterion, in that it can be checked without already knowing the answer.