Metric spaces isolate the part of real analysis depending only on distance. Compactness is the finiteness principle that makes local control uniform and turns sequences into convergent subsequences.
Metric topology
Open sets, closed sets, and convergence are all described by balls.
Definition. A metric on \(X\) is a function \(d:X\times X\to[0,\infty)\) that separates points, is symmetric, and satisfies the triangle inequality. The open ball \(B(x,r)\) is \(\{y:d(x,y)\lt r\}\).
Proposition. A set \(F\subset X\) is closed if and only if every convergent sequence in \(F\) has its limit in \(F\).
Proof. If \(F\) is closed and \(x_n\in F\), \(x_n\to x\notin F\), then the open complement contains a ball around \(x\), eventually excluding \(x_n\), contradiction. Conversely, if \(F\) is not closed, some \(x\in\overline F\setminus F\). Choose \(x_n\in F\cap B(x,1/n)\); then \(x_n\to x\notin F\).
Proposition. A map \(f:(X,d_X)\to(Y,d_Y)\) is continuous at \(x\) if and only if \(x_n\to x\) implies \(f(x_n)\to f(x)\).
Proof. The \(\varepsilon\)-\(\delta\) definition immediately gives the sequential implication. Conversely, if continuity fails at \(x\), there is \(\varepsilon_0>0\) such that for every \(n\) one can choose \(x_n\in B(x,1/n)\) with \(d_Y(f(x_n),f(x))\ge\varepsilon_0\). Then \(x_n\to x\), but \(f(x_n)\not\to f(x)\).
Sequential compactness
In metric spaces, compactness can be tested by sequences.
Definition. A metric space is sequentially compact if every sequence has a convergent subsequence whose limit lies in the space.
Theorem. In metric spaces, compactness by open covers is equivalent to sequential compactness.
Proof. Suppose first that \(X\) is compact. For each \(k\), a finite cover by balls of radius \(2^{-k}\) exists. Starting with any sequence, choose a subsequence contained in one ball from the first cover, then a further subsequence contained in one ball from the second cover, and continue. The diagonal subsequence \((x_{n_k})\) satisfies \(d(x_{n_j},x_{n_k})<2^{1-k}\) for \(j\ge k\), hence is Cauchy. Compact metric spaces are complete: any Cauchy sequence has a cluster point by compactness, and the Cauchy property forces the whole sequence to converge to it.
Conversely, assume sequential compactness. First, \(X\) is totally bounded. Otherwise some \(\varepsilon>0\) admits no finite \(\varepsilon\)-net; recursively choose \(x_{n+1}\) outside \(\bigcup_{j\le n}B(x_j,\varepsilon)\). Then \(d(x_i,x_j)\ge\varepsilon\) for \(i\ne j\), so no subsequence can converge, a contradiction.
Now let \(\mathcal U\) be an open cover. We claim it has a Lebesgue number: some \(\delta>0\) such that every \(\delta\)-ball lies in one member of \(\mathcal U\). If not, for every \(n\) choose \(x_n\) whose \(1/n\)-ball is contained in no member. A subsequence converges to \(x\), and some \(U\in\mathcal U\) contains \(B(x,r)\). Eventually \(d(x_{n_k},x)<r/2\) and \(1/n_k<r/2\), so \(B(x_{n_k},1/n_k)\subset U\), contradiction. A finite \(\delta/2\)-net now gives finitely many \(\delta\)-balls, each lying in a member of \(\mathcal U\); those members form a finite subcover.
Total boundedness and completeness
Compactness is exactly completeness plus finite approximability at every scale.
Definition. A metric space is totally bounded if for every \(\varepsilon>0\) it can be covered by finitely many balls of radius \(\varepsilon\).
Theorem. A metric space is compact if and only if it is complete and totally bounded.
Proof. Compact spaces are totally bounded by applying a finite subcover to all \(\varepsilon\)-balls, and complete because Cauchy sequences have convergent subsequences whose limit then attracts the whole sequence. Conversely, total boundedness lets one extract a Cauchy subsequence by repeatedly choosing balls of radius \(2^{-k}\) containing infinitely many terms; completeness gives a limit, proving sequential compactness.
Example (bounded is weaker than totally bounded). Let \(X\) be an infinite set with the discrete metric \(d(x,y)=1\) for \(x\ne y\). Its diameter is \(1\), so it is bounded. But every ball of radius \(1/2\) is a singleton, and no finite collection covers \(X\). Thus \(X\) is complete and bounded but not compact.
Continuous images
Compactness survives continuous maps and produces extrema.
Proposition. If \(f:X\to Y\) is continuous and \(K\subset X\) is compact, then \(f(K)\) is compact. If \(Y=\mathbb R\), then \(f\) attains its maximum and minimum on \(K\).
Proof. An open cover of \(f(K)\) pulls back to an open cover of \(K\), which has a finite subcover; pushing forward gives a finite subcover of \(f(K)\). A compact subset of \(\mathbb R\) is closed and bounded, so its supremum and infimum belong to it.
Theorem (Heine-Cantor). A continuous map from a compact metric space into a metric space is uniformly continuous.
Proof. If uniform continuity failed, there would be \(\varepsilon_0>0\) and pairs \(x_n,y_n\) with \(d_X(x_n,y_n)<1/n\) but \(d_Y(f(x_n),f(y_n))\ge\varepsilon_0\). Compactness gives a subsequence \(x_{n_k}\to x\). Since \(d_X(x_{n_k},y_{n_k})\to0\), also \(y_{n_k}\to x\). Continuity then makes both image subsequences converge to \(f(x)\), contradicting their fixed positive separation.
Heine-Borel in Euclidean space
Euclidean compactness has a simple closed-and-bounded form.
Theorem. A subset of \(\mathbb R^d\) is compact if and only if it is closed and bounded.
Proof. Closed subsets of compact spaces are compact, and boxes \([-M,M]^d\) are compact by repeated bisection or by product compactness. Thus closed bounded sets are compact. Conversely, compact sets are bounded by finitely many unit balls and closed because metric compact sets contain limits of their convergent sequences.