In mathematics, in general topology, compactification is the process or result of making a topological space into a compact space. A compact space is a space in which every open cover of the space contains a finite subcover. The methods of compactification are various, but each is a way of controlling points from "going off to infinity" by in some way adding "points at infinity" or preventing such an "escape".
Consider the real line with its ordinary topology. This space is not compact; in a sense, points can go off to infinity to the left or to the right. It is possible to turn the real line into a compact space by adding a single "point at infinity" which we will denote by ∞. The resulting compactification can be thought of as a circle (which is compact as a closed and bounded subset of the Euclidean plane). Every sequence that ran off to infinity in the real line will then converge to ∞ in this compactification.
Intuitively, the process can be pictured as follows: first shrink the real line to the open interval (-π,π) on the x-axis; then bend the ends of this interval upwards (in positive y-direction) and move them towards each other, until you get a circle with one point (the topmost one) missing. This point is our new point ∞ "at infinity"; adding it in completes the compact circle.
A bit more formally: we represent a point on the unit circle by its angle, in radians, going from -π to π for simplicity. Identify each such point θ on the circle with the corresponding point on the real line tan(θ/2). This function is undefined at the point π, since tan(π/2) is undefined; we will identify this point with our point ∞.
Since tangents and inverse tangents are both continuous, our identification function is a homeomorphism between the real line and the unit circle without ∞. What we have constructed is called the Alexandroff one-point compactification of the real line, discussed in more generality below. It is also possible to compactify the real line by adding two points, +∞ and -∞; this results in the extended real line.
An embedding of a topological space X as a dense subset of a compact space is called a compactification of X. It is often useful to embed topological spaces in compact spaces, because of the special properties compact spaces have.
Embeddings into compact Hausdorff spaces may be of particular interest. Since every compact Hausdorff space is a Tychonoff space, and every subspace of a Tychonoff space is Tychonoff, we conclude that any space possessing a Hausdorff compactification must be a Tychonoff space. In fact, the converse is also true; being a Tychonoff space is both necessary and sufficient for possessing a Hausdorff compactification.
The fact that large and interesting classes of non-compact spaces do in fact have compactifications of particular sorts makes compactification a common technique in topology.
Of particular interest are Hausdorff compactifications, i.e., compactifications in which the compact space is Hausdorff. A topological space has a Hausdorff compactification if and only if it is Tychonoff. In this case, there is a unique (up to homeomorphism) "most general" Hausdorff compactification, the Stone–Čech compactification of X, denoted by βX; formally, this exhibits the category of Compact Hausdorff spaces and continuous maps as a reflective subcategory of the category of Tychonoff spaces and continuous maps.
"Most general" or formally "reflective" means that the space βX is characterized by the universal property that any continuous function from X to a compact Hausdorff space K can be extended to a continuous function from βX to K in a unique way. More explicitly, βX is a compact Hausdorff space containing X such that the induced topology on X by βX is the same as the given topology on X, and for any continuous map f:X → K, where K is a compact Hausdorff space, there is a unique continuous map g:βX → K for which g restricted to X is identically f.
The Stone–Čech compactification can be constructed explicitly as follows: let C be the set of continuous functions from X to the closed interval [0,1]. Then each point in X can be identified with an evaluation function on C. Thus X can be identified with a subset of [0,1]C, the space of all functions from C to [0,1]. Since the latter is compact by Tychonoff's theorem, the closure of X as a subset of that space will also be compact. This is the Stone–Čech compactification. 
Walter Benz and Isaak Yaglom have shown how stereographic projection onto a single-sheet hyperboloid can be used to provide a compactification for split complex numbers. In fact, the hyperboloid is part of a quadric in real projective four-space. The method is similar to that used to provide a base manifold for group action of the conformal group of spacetime.
Real projective space RPn is a compactification of Euclidean space Rn. For each possible "direction" in which points in Rn can "escape", one new point at infinity is added (but each direction is identified with its opposite). The Alexandroff one-point compactification of R we constructed in the example above is in fact homeomorphic to RP1. Note however that the projective plane RP2 is not the one-point compactification of the plane R2 since more than one point is added.
Complex projective space CPn is also a compactification of Cn; the Alexandroff one-point compactification of the plane C is (homeomorphic to) the complex projective line CP1, which in turn can be identified with a sphere, the Riemann sphere.
Passing to projective space is a common tool in algebraic geometry because the added points at infinity lead to simpler formulations of many theorems. For example, any two different lines in RP2 intersect in precisely one point, a statement that is not true in R2. More generally, Bézout's theorem, which is fundamental in intersection theory, holds in projective space but not affine space. This distinct behavior of intersections in affine space and projective space is reflected in algebraic topology in the cohomology rings – the cohomology of affine space is trivial, while the cohomology of projective space is non-trivial and reflects the key features of intersection theory (dimension and degree of a subvariety, with intersection being Poincaré dual to the cup product).
Compactification of moduli spaces generally require allowing certain degeneracies – for example, allowing certain singularities or reducible varieties. This is notably used in the Deligne–Mumford compactification of the moduli space of algebraic curves.
For example, modular curves are compactified by the addition of single points for each cusp, making them Riemann surfaces (and so, since they are compact, algebraic curves). Here the cusps are there for a good reason: the curves parametrize a space of lattices, and those lattices can degenerate ('go off to infinity'), often in a number of ways (taking into account some auxiliary structure of level). The cusps stand in for those different 'directions to infinity'.
That is all for lattices in the plane. In n-dimensional Euclidean space the same questions can be posed, for example about SO(n)\SLn(R)/SLn(Z). This is harder to compactify. There are a variety of compactifications, such as the Borel–Serre compactification, the reductive Borel-Serre compactification, and the Satake compactifications, that can be formed.