Local data that glues — how sheaves encode "functions defined on open sets" consistently
A sheaf is a tool for organizing local data that can be glued together consistently. Think of it this way: if you know a function on each piece of a cover, and the functions agree on overlaps, there should be a unique global function matching them all. This "local-to-global" principle — formalized by the locality and gluing axioms — is what distinguishes a sheaf from a mere presheaf.
The structure sheaf 𝒪X on Spec(R) assigns to each basic open set D(f) the localization Rf — the ring obtained by formally inverting f. This is the algebraic analog of "regular functions that are allowed to have f in the denominator." The stalk at a prime 𝔭 is the local ring R𝔭, giving an infinitesimal picture of the geometry at that point. Together, the topological space and the structure sheaf form a locally ringed space — the foundation of scheme theory.
A presheaf ℱ on a topological space X assigns a set (or ring, module, etc.) ℱ(U) to each open set U, together with restriction maps ℱ(U) → ℱ(V) whenever V ⊆ U. A presheaf becomes asheaf when it satisfies two axioms: locality (if a section restricts to zero on every piece of a cover, it is zero) and gluing (if sections on overlapping pieces agree, they glue to a global section).
Not every presheaf is a sheaf, but every presheaf has a canonical sheafification — the "closest" sheaf that agrees with the presheaf on stalks. Sheafification adds exactly the missing glued sections. This process is analogous to completing a metric space: you don't change the local picture, but you ensure global consistency.
On X = Spec(R), the structure sheaf 𝒪X is defined by 𝒪X(D(f)) = Rf. For a general open set U, sections of 𝒪X(U) are functions that locally look like fractions a/f with f not vanishing. The key computation is the stalk at a prime 𝔭: the direct limit over all open neighborhoods of 𝔭 gives 𝒪X,𝔭 = R𝔭, the localization of R at 𝔭.
The local ring R𝔭 has a unique maximal ideal 𝔭R𝔭, and its residue field is the "value" of a function at the point 𝔭. This is why we call (Spec(R), 𝒪X) a locally ringed space — the stalk at every point is a local ring. The local ring captures infinitesimal information: its dimension tells you the local dimension, and its regularity tells you whether the point is smooth.