---
title: Compactness
module: Metric Spaces and Topology
moduleNumber: 3
lessonNumber: 4
order: 304
summary: >
  A set is compact if every open cover has a finite subcover. In a metric
  space this is equivalent to sequential compactness and to being complete and
  totally bounded. Compact sets are closed and bounded; the Heine–Borel theorem
  gives the converse in $\mathbb{R}^n$ but nowhere else in general.
topics: [Metric Spaces and Topology]
draft: false
sources:
  - book: Lebl
    ref: "Ch. 7 — Metric Spaces; §7.4 Completeness and compactness"
  - book: Rosenlicht
    ref: "Ch. 3 — Metric spaces"
---

The deepest theorems of single-variable analysis hold on closed bounded
intervals: a continuous function on $[a, b]$ attains its extremes, is
uniformly continuous, and is Riemann integrable. **Compactness** is the property
behind all three, isolated so it can be stated in any metric space. It has
three equivalent formulations, a covering condition, a sequential condition,
and a finiteness-plus-completeness condition, which coincide in a metric space. The
[Heine–Borel theorem](/real-analysis/foundations/intervals-uncountability) then
identifies the compact subsets of $\mathbb{R}^n$ as exactly the closed bounded
ones.

## The covering definition

> **Definition (Open cover, compact).** An **open cover** of $K \subseteq X$ is
> a collection $\{U_\lambda\}_{\lambda \in I}$ of open sets with $K \subseteq
> \bigcup_{\lambda} U_\lambda$. The set $K$ is **compact** if every open cover
> of $K$ has a **finite subcover**: finitely many indices $\lambda_1, \dots,
> \lambda_m$ with $K \subseteq \bigcup_{j=1}^m U_{\lambda_j}$.

The quantifier order is the whole content: no matter how the cover is chosen,
however large or pathological, finitely many of its sets already suffice. This
turns infinitely many local facts (each point sits in some $U_\lambda$) into one
global fact (a fixed finite list covers everything), which is why compactness
converts pointwise information into uniform information.[^lebl-742]

$$
% caption: Compactness: from an infinite open cover of $K$ (left), finitely
% many sets already cover $K$ (right).
\begin{tikzpicture}[scale=0.95, font=\small]
\definecolor{acc}{HTML}{4A6FA5}
% left: infinite cover
\begin{scope}
\draw[black, thick, fill=acc!8] plot[smooth cycle, tension=0.7]
  coordinates {(0,0) (2.4,-0.3) (3.0,1.4) (1.6,2.2) (-0.4,1.4)};
\node[black] at (1.2,1.0) {$K$};
\foreach \c/\r in {{(0.3,0.6)}/0.7, {(1.2,0.2)}/0.7, {(2.1,0.6)}/0.7,
  {(2.4,1.5)}/0.7, {(1.3,1.7)}/0.7, {(0.1,1.3)}/0.7, {(1.7,1.1)}/0.6} {
  \draw[black] \c circle (\r);
}
\node[font=\scriptsize] at (1.3,-0.9) {infinite cover $\{U_i\}$};
\end{scope}
% right: finite subcover
\begin{scope}[xshift=6.2cm]
\draw[black, thick, fill=acc!8] plot[smooth cycle, tension=0.7]
  coordinates {(0,0) (2.4,-0.3) (3.0,1.4) (1.6,2.2) (-0.4,1.4)};
\node[black] at (1.2,1.0) {$K$};
\foreach \c/\r in {{(0.5,0.7)}/1.0, {(2.0,0.8)}/1.0, {(1.3,1.7)}/0.95} {
  \draw[acc, thick] \c circle (\r);
}
\node[font=\scriptsize] at (1.3,-0.9) {finite subcover};
\end{scope}
\end{tikzpicture}
$$

**First examples.** Finiteness of the subcover is a strong demand.

- **$\{0\}$ and every finite set are compact:** pick one cover-set through each
  of the finitely many points.
- **$\mathbb{R}$ is not compact:** the cover $\{(-j, j)\}_{j \in \mathbb{N}}$
  has no finite subcover, since a finite union is the largest single interval
  $(-j_m, j_m)$, missing $j_m$.
- **$(0, 1)$ is not compact:** for the cover $\{(1/j,\ 1 - 1/j)\}$, a finite
  union is the largest single interval $(1/j_m,\ 1 - 1/j_m)$, which misses
  points near the endpoints.

The two failures are different: $\mathbb{R}$ is unbounded, $(0,1)$ is bounded
but not closed. Either property rules out compactness, and in $\mathbb{R}^n$
they are the only obstructions.

## Compact implies closed and bounded

> **Proposition.** A compact subset $K$ of any metric space is closed and
> bounded.

**Bounded.** Fix $p \in X$. The balls $\{B(p, n)\}_{n \in \mathbb{N}}$ cover
$K$ (they cover all of $X$), so a finite subcover puts $K$ inside a single
$B(p, n_m)$.

**Closed.** If some $x \in \overline{K} \setminus K$, the complements of the
closed balls $C(x, 1/n)$ form an open cover of $K$ (their union omits only
$x$), but any finite subfamily reduces to a single $C(x, 1/n_m)^c$ that still
misses points of $K$ near $x$, since $x \in \overline{K}$. No finite subcover
exists, so $K$ cannot be compact unless it is closed.

$$
% caption: Compact forces bounded (left): finitely many growing balls about
% $p$ trap $K$. And closed (right): the shrinking closed balls about a missing
% closure point $x$ leave no finite subcover of $K$.
\begin{tikzpicture}[scale=0.95, font=\small]
\definecolor{acc}{HTML}{4A6FA5}
% left
\begin{scope}
\foreach \r in {0.8,1.4,2.0} {\draw[black] (0,0) circle (\r);}
\fill[acc] (0,0) circle (1.5pt);
\node[below] at (0,0) {$p$};
\draw[black, thick, fill=acc!8] plot[smooth cycle, tension=0.8]
  coordinates {(0.6,0.2) (1.3,-0.4) (1.6,0.7) (1.0,1.2) (0.3,0.9)};
\node[black] at (1.0,0.4) {$K$};
\node[font=\scriptsize] at (0,-2.4) {bounded};
\end{scope}
% right
\begin{scope}[xshift=6cm]
\draw[black, thick, fill=white] (0,0) circle (2.4pt);
\node[below] at (0,-0.05) {$x$};
\foreach \r in {0.5,0.9,1.5} {\draw[black] (0,0) circle (\r);}
\draw[black, thick, fill=acc!8] plot[smooth cycle, tension=0.8]
  coordinates {(0.7,0.3) (1.7,0.1) (2.1,1.1) (1.2,1.6) (0.5,1.0)};
\node[black] at (1.3,0.8) {$K$};
\node[font=\scriptsize] at (0,-2.4) {closed};
\end{scope}
\end{tikzpicture}
$$

The converse, closed and bounded implies compact, is _false_ in general and
holds only under extra structure. Two counterexamples show where it breaks:

- In $C[0,1]$ the closed unit ball is closed and bounded but not compact: a
  sequence of functions with $d(f_n, 0) = 1$ and $d(f_n, f_k) = 1$ for $n \ne
  k$ has no convergent subsequence.
- Under the discrete metric on an infinite set, every subset is closed and
  bounded, yet only the finite subsets are compact.

> **Worked example (Closed unit ball of $C[0,1]$ is not compact).** The
> functions $f_n(t) = t^n$ lie in the closed unit ball, since
> $\lVert f_n \rVert_\infty = \sup_{t \in [0,1]} t^n = 1$. Pointwise,
> $$
> f_n(t) \to \begin{cases} 0 & 0 \le t < 1, \\ 1 & t = 1, \end{cases}
> $$
> a discontinuous limit. A uniformly convergent subsequence would have a
> continuous limit, and a uniform limit forces the pointwise limit, so its
> limit would have to be this discontinuous function — impossible in $C[0,1]$.
> Hence $\{f_n\}$ has no subsequence converging in $C[0,1]$: the closed unit
> ball is not sequentially compact, so it is not compact.

Bounded is too weak in infinite-dimensional or discrete spaces; the right
strengthening is total boundedness, below.

## Sequential compactness

The extreme value theorem rests on a condition about sequences, not covers,
and in a metric space it is equivalent to compactness.

> **Definition (Sequential compactness).** $K \subseteq X$ is **sequentially
> compact** if every sequence in $K$ has a subsequence converging to a point of
> $K$.

> **Theorem (Compact $=$ sequentially compact).** In a metric space, $K$ is
> compact if and only if $K$ is sequentially compact.

One direction: if $K$ is compact and some sequence $\{x_n\}$ had no convergent
subsequence in $K$, then each $x \in K$ would have a ball containing only
finitely many terms; these balls cover $K$, a finite subfamily contains only
finitely many terms in total, yet must contain all of $K$ and hence all terms,
a contradiction. The other direction runs through a covering lemma that produces a
single radius working uniformly across a sequentially compact set.

> **Lemma (Lebesgue number).** If every sequence in $K$ has a subsequence
> converging in $K$, then for every open cover $\{U_\lambda\}$ of $K$ there is a
> $\delta > 0$ such that every ball $B(x, \delta)$, $x \in K$, lies inside some
> single $U_\lambda$.

The uniform radius $\delta$ (depending on the cover, not on $x$) lets one pick
points $x_1, x_2, \dots$ in $K$ with pairwise distance at least $\delta$, each
$B(x_j, \delta)$ inside a cover-set; by sequential compactness the selection
cannot continue forever, so the process halts with a finite subcover.

## Total boundedness and the three-way equivalence

The correct strengthening of "bounded" is finiteness at every scale.

> **Definition (Totally bounded).** $S \subseteq X$ is **totally bounded** if
> for every $\varepsilon > 0$ there are finitely many points $x_1, \dots, x_n$
> with $S \subseteq \bigcup_{j=1}^n B(x_j, \varepsilon)$. The centers form a
> finite **$\varepsilon$-net**.

Total boundedness requires that $S$ be coverable by finitely many balls of _any_
prescribed radius, a far stronger condition than fitting inside one large ball.
It rules out the infinite discrete set (balls of radius $\tfrac12$ are
singletons, and infinitely many are needed) and the $C[0,1]$ unit ball. With it,
compactness in a metric space has three equivalent descriptions.

> **Theorem (Characterizations of compactness).** For $K$ in a metric space,
> the following are equivalent:
>
> - $K$ is **compact** (every open cover has a finite subcover);
> - $K$ is **sequentially compact** (every sequence has a convergent
>   subsequence in $K$);
> - $K$ is **complete and totally bounded**.

$$
% caption: The three equivalent forms of compactness in a metric space; any
% one may be taken as the definition.
\begin{tikzpicture}[scale=1.0, font=\small,
  box/.style={draw, thick, align=center, minimum width=30mm, minimum height=12mm, font=\footnotesize}]
\definecolor{acc}{HTML}{4A6FA5}
\node[box, draw=acc] (cov) at (0,2.4) {open-cover\\compact};
\node[box] (seq) at (-3.0,-0.6) {sequentially\\compact};
\node[box] (tot) at (3.0,-0.6) {complete and\\totally bounded};
\draw[acc, thick, <->] (cov) -- (seq);
\draw[acc, thick, <->] (cov) -- (tot);
\draw[acc, thick, <->] (seq) -- (tot);
\end{tikzpicture}
$$

Completeness and total boundedness separate the two failure modes cleanly.
$(0,1)$ is totally bounded but not complete; an infinite discrete space is
complete but not totally bounded; each is missing exactly one half of
compactness. In a complete space the theorem specializes: $K$ is
compact iff it is closed and totally bounded, because a closed subset of a
complete space is itself [complete](/real-analysis/metric-spaces/convergence-completeness).

## The Heine–Borel theorem

In $\mathbb{R}^n$, bounded sets are automatically totally bounded (a box is
tiled by finitely many small subboxes), so the extra hypothesis is free and
the familiar criterion holds.

> **Theorem (Heine–Borel).** A subset $K \subseteq \mathbb{R}^n$ is compact if
> and only if it is closed and bounded.

The forward direction is the general proposition above. For the converse, a
closed bounded $K \subseteq \mathbb{R}^n$ sits inside a box $[a_1, b_1] \times
\cdots \times [a_n, b_n]$; repeatedly extracting convergent subsequences
coordinate by coordinate, using
[Bolzano–Weierstrass](/real-analysis/sequences-series/limsup-bolzano-weierstrass)
in each, produces a subsequence converging in the box, and closedness keeps the
limit in $K$. So $K$ is sequentially compact, hence compact.

$$
% caption: In $\mathbb{R}^n$ a closed bounded box is compact (left); dropping
% either closedness or boundedness breaks it (right).
\begin{tikzpicture}[scale=1.0, font=\small]
\definecolor{acc}{HTML}{4A6FA5}
% compact box
\draw[acc, thick, fill=acc!10] (0,0) rectangle (2,1.6);
\node[acc] at (1,0.8) {compact};
\node[font=\scriptsize] at (1,-0.45) {closed and bounded};
% open square (not closed)
\draw[black, thick, dashed] (3.4,0) rectangle (5.4,1.6);
\node[black] at (4.4,0.8) {open};
\node[font=\scriptsize] at (4.4,-0.45) {not closed};
% unbounded strip
\draw[black, thick] (6.4,0) -- (9.0,0);
\draw[black, thick] (6.4,1.6) -- (9.0,1.6);
\draw[black, thick] (6.4,0) -- (6.4,1.6);
\draw[black, thick, ->] (7.4,0.8) -- (9.2,0.8);
\node[font=\scriptsize] at (7.7,-0.45) {not bounded};
\end{tikzpicture}
$$

Heine–Borel is a theorem _about $\mathbb{R}^n$_, resting on Bolzano–Weierstrass
and thus on the completeness of $\mathbb{R}$. It does not extend to general
metric spaces, nor even to every subspace of $\mathbb{R}^n$; the $C[0,1]$ unit
ball is the standard counterexample showing that closed and bounded is not
enough once the dimension is infinite.

> **Worked example (Heine–Borel applied).** The unit sphere $S^{n-1} = \{ x \in
> \mathbb{R}^n : \lVert x \rVert_2 = 1 \}$ is compact. It is bounded, sitting
> inside $C(0, 1)$. It is closed: it is the preimage $g^{-1}(\{1\})$ of the
> closed set $\{1\}$ under the continuous map $g(x) = \lVert x \rVert_2$, so its
> complement is open. Closed and bounded in $\mathbb{R}^n$ gives compact by
> Heine–Borel. The same argument makes the closed annulus $\{ 1 \le \lVert x
> \rVert_2 \le 2 \}$ compact, while the open ball $B(0, 1)$ fails (not closed)
> and the closed half-space $\{ x_1 \ge 0 \}$ fails (not bounded).

## A worked compact set

> **Worked example ($\{1/n\} \cup \{0\}$ is compact).** The set $A = \{1/n : n
> \in \mathbb{N}\} \cup \{0\} \subseteq \mathbb{R}$ is compact directly from the
> definition, and the argument shows the role of the limit point $0$. Given any
> open cover $\{U_\lambda\}$, some $U_{\lambda_0}$ contains $0$; being open, it
> contains a ball $(-\delta, \delta)$, which already holds all but finitely many
> of the points $1/n$ (those with $1/n < \delta$). Each of the finitely many
> remaining points needs just one cover-set, so $U_{\lambda_0}$ together with
> those finitely many sets is a finite subcover. The same set _without_ $0$,
> namely $\{1/n\}$ alone, is not compact: the sets $(1/(n+1), 2/n)$ cover it but
> no finite subfamily reaches arbitrarily small $1/n$. One limit point is the
> entire difference between compact and non-compact here.

$$
% caption: Compactness of $\{1/n\} \cup \{0\}$: one cover-set through $0$
% swallows the whole tail of the sequence, leaving finitely many points to
% cover individually.
\begin{tikzpicture}[scale=1.0, font=\small]
\definecolor{acc}{HTML}{4A6FA5}
\draw[black, thick] (-0.6,0) -- (6.8,0);
% ball around 0 covering the tail
\draw[acc, thick, fill=acc!10] (0,0) ellipse (1.5 and 0.55);
\node[acc, below, font=\scriptsize] at (0,-0.6) {cover-set through $0$};
\fill[black] (0,0) circle (2pt);
\node[above, yshift=1pt] at (0,0.08) {$0$};
% tail points inside ball: 1/5, 1/6, ... at 6/n scale => 1.2, 1.0, 0.86...
\foreach \x in {1.2, 1.0, 0.86, 0.75, 0.66, 0.6, 0.545, 0.5} {
  \fill[acc] (\x,0) circle (1.4pt);
}
% remaining finitely many points, each with its own small cover-set
\foreach \x/\lab in {6.0/1, 3.0/{\frac12}, 2.0/{\frac13}, 1.5/{\frac14}} {
  \draw[black] (\x,0) ellipse (0.28 and 0.3);
  \fill[acc] (\x,0) circle (1.8pt);
  \node[above, font=\scriptsize] at (\x,0.35) {$\lab$};
}
\node[black, font=\scriptsize] at (4.5,-0.65) {each remaining point covered alone};
\end{tikzpicture}
$$

## Nested compact sets and the finite intersection property

Compactness has a dual phrasing in terms of closed sets, obtained by
complementing the cover definition.

> **Proposition (Finite intersection property).** $K$ is compact iff every
> collection of closed subsets of $K$ with the **finite intersection property**,
> every finite subcollection has nonempty intersection, has nonempty total
> intersection.

Complementing a would-be cover with no finite subcover produces closed sets
with the finite intersection property but empty intersection, and conversely.
The most-used consequence is a Cantor-style nesting result.

> **Theorem (Nested compacts).** If $K_1 \supseteq K_2 \supseteq \cdots$ are
> nonempty compact sets, then $\bigcap_{n} K_n \ne \emptyset$.

The $K_n$ are closed subsets of the compact $K_1$, and any finite subfamily
intersects in the smallest listed set, which is nonempty; the finite
intersection property then forces the full intersection to be nonempty. This is
the compact-set counterpart of the [nested closed
balls](/real-analysis/metric-spaces/convergence-completeness) in a complete
space, and it underlies existence proofs that produce a point as the sole
common element of a shrinking family.

## Stability and use

Compactness passes to closed subsets and does not depend on the ambient
space.

> **Proposition.** A closed subset of a compact set is compact. A compact set
> is complete. Compactness is intrinsic: $K$ is compact in $(X, d)$ iff it is
> compact as a space in its own subspace metric.

The last point contrasts sharply with closedness, which depends on the ambient
space; compactness does not, so one may speak of a compact space without naming
where it sits. This makes compactness the right hypothesis for the strongest
continuity theorems: the continuous image of a compact set is compact, which
yields the [extreme value theorem](/real-analysis/continuity/evt-ivt), and
continuity on a compact set is automatically uniform.

[^lebl-742]: **Lebl**, _Basic Analysis I_, §7.4.2 — Compactness: the open-cover definition, compact implies closed and bounded, the Lebesgue covering lemma, equivalence of compactness and sequential compactness, total boundedness, and the Heine–Borel theorem.
