---
title: "Compactness in Metric Spaces"
description: "Compare the open-cover and sequential definitions, prove they agree in a metric space, and see what compactness implies for continuous functions."
canonical: https://lightmysky.com/learn/mathematics/compactness-in-metric-spaces-mt_dBLXU0wSN9
source: https://lightmysky.com/learn/mathematics/compactness-in-metric-spaces-mt_dBLXU0wSN9.md
retrieved: 2026-11-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# Compactness in Metric Spaces

Compare the open-cover and sequential definitions, prove they agree in a metric space, and see what compactness implies for continuous functions.

Subject: Mathematics · Area: Topology · Ages 21 to 22
Page: https://lightmysky.com/learn/mathematics/compactness-in-metric-spaces-mt_dBLXU0wSN9

## Ready when they can

- Prove that continuous maps preserve compactness and that continuous real-valued functions on nonempty compact domains attain both bounds
- Use completeness, total boundedness and separated sequences to distinguish compactness from closedness and boundedness
- Prove the equivalence of open-cover and sequential compactness in metric spaces and identify the completeness step in Heine-Borel

## Lesson: Compact domains tame functions

You have used completeness to obtain limits of Cauchy sequences. Compactness adds another requirement. In a metric space X, write B(x,r)={y:d(x,y)<r}. An open cover is a family of open sets covering X. X is compact if every open cover has a finite subcover. It is sequentially compact if every sequence has a subsequence converging in X. A subsequence uses strictly increasing indices. For metric spaces, these two compactness definitions agree.

Suppose X is compact. If every ball about some x contains infinitely many indexed terms, choose increasing indices with distances to x below 1/j. This gives a convergent subsequence. Otherwise every x has a ball containing only finitely many indexed terms. These balls cover X. A finite subcover would contain only finitely many indices, a contradiction. Thus X is sequentially compact.

X is totally bounded if, for every ε>0, finitely many open ε-balls centred in X cover X. Sequential compactness implies total boundedness. Otherwise, for some ε, choose each new point outside the ε-balls about all earlier points. Distinct chosen points remain at least ε apart. No subsequence is Cauchy, so none converges. This contradicts sequential compactness.

Now suppose X is sequentially compact and fix an open cover. We claim some δ>0 makes every B(x,δ) lie in a cover member. If not, choose x_n such that B(x_n,1/n) lies in none. Select a subsequence x_(n_j) converging to x. A cover member U containing x contains B(x,r) for some r>0. Eventually d(x_(n_j),x)<r/2 and 1/n_j<r/2. The triangle inequality puts B(x_(n_j),1/n_j) inside U, a contradiction.

Total boundedness now gives a finite cover by δ/2-balls, centred at c_1,...,c_N. For each centre choose an original cover member containing B(c_i,δ). It also contains B(c_i,δ/2). Thus at most N original members cover X, proving compactness. This completes the metric equivalence of open-cover and sequential compactness. The empty space satisfies both definitions directly.

A metric space is compact exactly when it is complete and totally bounded. We already proved total boundedness for compact spaces. To prove completeness, take a Cauchy sequence and a subsequence converging to x. For ε>0, choose a late subsequence term within ε/2 of x. All sufficiently late sequence terms are within ε/2 of that term. The triangle inequality gives distance below ε from x. The whole sequence converges to x.

Conversely, assume completeness and total boundedness. Cover X by finitely many balls of radius 2^(-j), for j=1,2,... . At each stage retain infinitely many previous indices in one ball, then select an index larger than the last selected index. The retained index groups are nested. Any two selected terms from stage j onward are less than 2^(1-j) apart. This is a Cauchy subsequence. Completeness gives its limit in X, proving compactness.

Heine-Borel: a subset of Euclidean R^m is compact exactly when it is closed and bounded. A bounded set lies in a box. Finite grids of small cells, with a centre chosen in each nonempty cell of the set, prove total boundedness. R^m is complete because each coordinate of a Cauchy sequence converges. A closed subset contains those limits and is complete. Conversely, compact subsets of metric spaces are closed and bounded.

In R, enclose a bounded sequence in a closed interval. Bisect it and retain a closed half with infinitely many indexed terms. Repeat within that half. The nested lengths tend to zero. Completeness supplies L=sup a_j for the left endpoints, with a_j≤L≤b_j for every j. Increasing indices chosen from the intervals give a subsequence converging to L in R. If the sequence lies in a closed subset K of R, then L belongs to K.

Let f:K→Y be continuous and K compact. Pull an open cover of f(K) back through f: preimages of open sets are open in K and cover K. Compactness selects finitely many preimages. Their corresponding original sets cover f(K), so the image is compact. If Y=R, the image is also bounded: the cover (-n,n), n≥1, has a finite subcover.

For nonempty compact A in R, boundedness gives M=sup A. Choose y_n in A with M-1/n<y_n≤M. A subsequence converges in A, and these inequalities force its limit to be M. Applying the argument to -A gives a minimum. Thus a continuous real-valued function on a nonempty compact domain attains both bounds. The empty set is compact, since every cover has an empty finite subcover, but a function on it attains no values.

Use the usual distance when comparing these sets. The interval [0,1] in R is nonempty, closed and bounded, hence compact. Every continuous real-valued function on it attains both bounds. On (0,1), the continuous function 1/x is unbounded. On Q intersect [0,1], choose irrational a in (0,1). The continuous function 1/|x-a| is defined but unbounded as rational inputs approach a. Neither set has the same guarantee.

For a quadratic, -x²+2ax=a²-(x-a)²≤a². On a closed interval containing a, equality at x=a gives maximum a². For example, -x²+4x on [0,5] has maximum 4 at x=2. Also, for 0≤u≤v, v²-u²=(v-u)(v+u)≥0. Squaring preserves order on nonnegative inputs, so the maximum of x² on [u,v] is v².

On (0,1], f(x)=-x has supremum 0 but no maximum: -1/n approaches 0, while -x=0 requires the excluded input 0. The sequence 1/n has no subsequence converging inside (0,1], so the domain is not compact. A missing endpoint does not prevent every extremum. On (0,b], where b>0, 1/x is unbounded above but has minimum 1/b at x=b. Positive x≤b gives 1/x≥1/b. Polynomials and reciprocals are continuous on their domains.

K=Q intersect [0,1], with distance |x-y|, is closed relative to Q: its complement in Q consists of the points below 0 or above 1 and is open. K is bounded and totally bounded, using finite short-interval covers. Rational approximations to sqrt(2)/2 form a Cauchy sequence with no limit in K. Every subsequence has that same irrational real limit. Thus K is incomplete and not compact. K is not closed in R.

The space ell^2 consists of real sequences x with sum x_j² finite and norm ||x||=sqrt(sum x_j²). Its closed unit ball is {x:||x||≤1}. Let e_n have coordinate 1 at position n and 0 elsewhere. Each has norm 1. For n≠m, ||e_n-e_m||=sqrt(2). No subsequence is Cauchy, so none converges. This closed bounded ball is not compact: it lacks total boundedness.

To count small balls, use separation. If distinct points p and q lie in one open ε-ball, the triangle inequality gives d(p,q)<2ε. Hence a ball of radius ε contains at most one point from a set whose pairwise distances are at least 2ε. Covering N such points needs at least N balls. N balls centred at the points suffice, giving an exact minimum.

A closed subset F of compact X is compact. Write each member of an open cover of F as F intersect U, where U is open in X. Add X\F to the U sets to cover X. A finite subcover exists. Discard X\F and take the corresponding original cover members; they cover F. Finite metric spaces are compact too: select one cover member for each point.

The sets U_n=(1/n,2), n≥1, form an open cover of (0,1]. For each x>0, choose an integer n>1/x. Then x belongs to U_n. In a finite selection let N be the largest index. Every selected set lies in U_N. The domain point 1/(N+1) is below 1/N, so no selected set contains it. This cover has no finite subcover.

An infinite set can still be compact. Let K={0} union {1/n:n≥1}. Given an open cover, choose a member U containing 0. It contains (-r,r) intersect K for some r>0. Therefore all sufficiently late terms 1/n lie in U. Only finitely many earlier terms remain. Choose one cover member for each remaining point. Together with U, these form a finite subcover.

**Recap.** Metric compactness means complete and totally bounded. In Euclidean R^m it means closed and bounded. Continuous real functions attain extrema on nonempty compact domains.

*This compactness lesson, its worked questions and flashcards were written for this dataset.*

## Practice

17 questions on this page, each with its working shown.

## Needs first

- [Completeness and the Contraction Mapping Theorem](https://lightmysky.com/learn/mathematics/completeness-and-the-contraction-mapping-theorem-mt_DYsLzg-IaK)
