Let XX be a topological space and A⊆X.A\subseteq X. An open cover of AA is a collection of open sets whose union contains A,A, and a subcover is a subcollection of an open cover that still covers A.A. The set AA is compact if and only if every open cover of AA has a finite subcover, and XX is a compact space if XX is compact as a subset of itself. Compactness of AA is a property of the subspace AA alone, so it does not depend on the space in which AA sits.

Finite sets are compact, R\mathbb{R} is not compact, since the open cover {(−n,n):n∈N}\left\{\left(-n,n\right):n\in\mathbb{N}\right\} has no finite subcover, and (0,1]\left(0,1\right] is not compact, since {(1n,2):n∈N}\left\{\left(\frac{1}{n},2\right):n\in\mathbb{N}\right\} has no finite subcover. A closed bounded interval [a,b]\left[a,b\right] is compact. Compact sets have the following properties:

  • a closed subset of a compact set is compact;
  • a compact subset of a Hausdorff space is closed;
  • a finite union of compact sets is compact;
  • the product of finitely many compact spaces is compact;
  • the continuous image of a compact set is compact.

The last property states that if f:X→Yf:X\rightarrow Y is continuous and A⊆XA\subseteq X is compact then f(A)f(A) is compact. Consequently a continuous bijection from a compact space onto a Hausdorff space is a homeomorphism, since it maps closed sets, which are compact, to compact sets, which are closed.

A set AA in a metric space is sequentially compact if and only if every sequence in AA has a subsequence that converges to a point of A,A, and totally bounded if and only if for every ε>0\varepsilon>0 it is covered by finitely many open balls of radius ε.\varepsilon. A totally bounded set is bounded, and in Rn\mathbb{R}^n the converse holds. In a metric space the following are equivalent:

  • AA is compact;
  • AA is sequentially compact;
  • AA is complete and totally bounded.

The Heine–Borel theorem states that a subset of Rn\mathbb{R}^n is compact if and only if it is closed and bounded. The Bolzano–Weierstrass theorem states that every bounded sequence in Rn\mathbb{R}^n has a convergent subsequence, which is the sequential compactness of closed balls. Neither holds in every metric space: the closed unit ball of an infinite-dimensional normed vector space is closed and bounded but not compact, and the discrete metric makes every infinite set closed, bounded and non-compact. The Lebesgue number lemma states that for every open cover of a compact metric space AA there exists δ>0\delta>0 such that every subset of AA with diameter less than δ\delta lies inside some set of the cover.

Let AA be a non-empty compact space and f:A→Rf:A\rightarrow\mathbb{R} be continuous. Since f(A)f(A) is a compact subset of R\mathbb{R} it is closed and bounded, so it contains its supremum and infimum: ff is bounded and attains its maximum and minimum.

∃ xmin⁡,xmax⁡∈A:f(xmin⁡)≤f(x)≤f(xmax⁡)  ∀ x∈A\exists\,x_{\min},x_{\max}\in A:f\left(x_{\min}\right)\leq f(x)\leq f\left(x_{\max}\right)\,\,\forall\,x\in A

This extends the extreme value theorem from closed bounded intervals to compact sets, and the Heine–Cantor theorem extends in the same way: a continuous function from a compact metric space to a metric space is uniformly continuous. If AA is a compact subset of a metric space and x∈Xx\in X then the distance d(x,A):=inf⁡a∈Ad(x,a)d(x,A):=\inf_{a\in A}d(x,a) is attained at some point of A,A, and two disjoint compact sets are at positive distance from one another.