The extreme value theorem and uniform continuity both used something special about $[a, b]$: every sequence in it has a subsequence converging in it. Compactness is the name for this property, stated in a form that works in every metric space. It builds on open sets.
🔑 Key idea
An open cover of $K$ is a collection of open sets whose union contains $K$. $K$ is compact when every open cover of $K$ has a finite subcover. In a metric space this is equivalent to: every sequence in $K$ has a subsequence converging to a point of $K$. Heine–Borel: in $\mathbb{R}^{n}$, $K$ is compact exactly when it is closed and bounded.
💡 Why it works
$[a, b]$ is compact. Take an open cover, and let $c$ be the supremum of the $x \in [a, b]$ for which $[a, x]$ is covered by finitely many sets of the cover ($x = a$ qualifies, so $c$ exists). Some set $U_0$ of the cover contains $c$, and with it an interval $(c - r, c + r)$. Pick a qualifying $x > c - r$: finitely many sets cover $[a, x]$, and adding $U_0$ covers $[a, t]$ for every $t < c + r$. If $c < b$, then $t = \min\left(c + \frac{r}{2}, b\right)$ qualifies and is larger than $c$, which is impossible. So $c = b$, and the same finite family covers $[a, b]$. $\blacksquare$
Bounded is not enough. The sets $\left(\frac{1}{n}, 2\right)$ cover $(0, 1]$, since every $x > 0$ has $\frac{1}{n} < x$ for large $n$. But finitely many of them have a largest $N$, and their union $\left(\frac{1}{N}, 2\right)$ misses $\frac{1}{2N}$. So $(0, 1]$ is not compact: it is not closed. Compact sets give back the theorems of unit 4 in full generality: a continuous function maps compact sets to compact sets, so a continuous real function on a compact set attains a maximum and a minimum.
An open cover of $[0, 4]$. "Find a finite subcover" chooses, from the left, the interval that reaches farthest at each step, the same idea as in the proof.The cover $\left(\frac{1}{n}, 2\right)$ of $(0, 1]$: with the slider, use more and more of the intervals. Each finite batch leaves a gap next to $0$.
Worked examples
✏️ Worked example: Choosing a finite subcover
The open intervals $(-1, 2)$, $(1, 3)$, $(0, 1.5)$, $(2.5, 5)$ cover $[0, 4]$. What is the smallest number of them that still covers?
Start at $0$: $(-1, 2)$ reaches farthest, to $2$.
The point $2$ is not in $(-1, 2)$; of the intervals containing $2$, $(1, 3)$ reaches farthest. Then $(2.5, 5)$ covers past $4$.
Answer: $3$; the interval $(0, 1.5)$ is not needed.
✏️ Worked example: How many intervals of the bad cover
How many of the sets $\left(\frac{1}{n}, 2\right)$ are needed to cover $\left[\frac{1}{10}, 1\right]$?
The union of the first $N$ is $\left(\frac{1}{N}, 2\right)$; it contains $\frac{1}{10}$ when $\frac{1}{N} < \frac{1}{10}$, that is $N \ge 11$.
Answer: $11$. The closed interval $\left[\frac{1}{10}, 1\right]$ is compact, so a finite number suffices; for $(0, 1]$ no number does.
✏️ Worked example: Which are compact?
Which of $[0, 1]$, $[0, \infty)$, $\{0\} \cup \left\{\frac{1}{n}\right\}$, $\mathbb{Q} \cap [0, 1]$ are compact?
Apply Heine–Borel: $[0, \infty)$ is unbounded; $\mathbb{Q} \cap [0, 1]$ is not closed.
Answer: $[0, 1]$ and $\{0\} \cup \left\{\frac{1}{n}\right\}$.
⚠️ Common mistake
Showing it for one cover. Finding a finite subcover of one particular open cover proves nothing about compactness; the definition is about every open cover. To show a set is not compact, you need one cover with no finite subcover. To show it is compact, use a theorem (Heine–Borel in $\mathbb{R}^{n}$, or the sequence criterion) or an argument that handles an arbitrary cover, like the supremum proof above.
Practice
Pass with 3 right answers, the last 2 in a row. Each right answer earns 3 XP.