[proofplan]
We reduce to the scalar case $m = 1$ by extending each coordinate function separately. On the open complement $U = \mathbb{R}^n \setminus K$, we construct a partition of unity $\{v_k\}_{k=1}^\infty$ subordinate to a countable dense subset $\{s_k\}_{k=1}^\infty \subset K$. Each partition function $v_k$ is built from bump functions $u_{s_k}$ that vanish outside a ball of radius $2\operatorname{dist}(x,K)$ centred at $s_k$, normalised by a sum $\sigma = \sum_k 2^{-k} u_{s_k}$. The extension is then $\bar{f}(x) = \sum_k v_k(x) f(s_k)$ on $U$ and $\bar{f} = f$ on $K$. Continuity on $U$ follows from locally uniform convergence via the [Weierstrass M-Test](/theorems/261), and continuity at boundary points $a \in K$ follows from [uniform continuity](/page/Uniform%20Continuity) of $f$ on $K$: the $\delta_1/4$ trick ensures that only nearby partition functions contribute.
[/proofplan]
[step:Reduce to the scalar case $m = 1$]
Write $f = (f_1, \dots, f_m)$ where each $f_i : K \to \mathbb{R}$ is continuous. If we can extend each scalar component $f_i$ to a continuous map $\bar{f}_i : \mathbb{R}^n \to \mathbb{R}$, then $\bar{f} = (\bar{f}_1, \dots, \bar{f}_m) : \mathbb{R}^n \to \mathbb{R}^m$ is continuous and satisfies $\bar{f}|_K = f$. We therefore assume $m = 1$ for the remainder of the proof.
We introduce the notation
\begin{align*}
\operatorname{dist}(x, K) &:= \inf_{y \in K} \|x - y\|, \\
U &:= \mathbb{R}^n \setminus K.
\end{align*}
Since $K$ is [compact](/page/Compact%20Space) (hence [closed](/page/Closed%20Set)), $U$ is open, and $\operatorname{dist}(x, K) > 0$ for every $x \in U$.
[/step]
[step:Construct auxiliary bump functions localised near points of $K$]
For each $s \in K$, define the auxiliary function
\begin{align*}
u_s : U &\to \mathbb{R} \\
x &\mapsto \max\!\left\{2 - \frac{\|x - s\|}{\operatorname{dist}(x, K)},\; 0\right\}.
\end{align*}
This function has three properties:
**(i) Continuity on $U$.** Both $x \mapsto \|x - s\|$ and $x \mapsto \operatorname{dist}(x, K)$ are continuous on $\mathbb{R}^n$. Since $\operatorname{dist}(x, K) > 0$ on $U$, the ratio $\|x - s\| / \operatorname{dist}(x, K)$ is continuous on $U$, and taking the maximum with $0$ preserves continuity.
**(ii) Bounded range.** For every $x \in U$, the triangle inequality gives $\|x - s\| \geq \operatorname{dist}(x, K)$ (since $s \in K$), so $\|x - s\| / \operatorname{dist}(x, K) \geq 1$, which yields $u_s(x) \leq 1$. The maximum with $0$ ensures $u_s(x) \geq 0$. Thus $0 \leq u_s(x) \leq 1$.
**(iii) Localised support.** If $\|x - s\| \geq 2\operatorname{dist}(x, K)$, then $2 - \|x - s\|/\operatorname{dist}(x, K) \leq 0$, so $u_s(x) = 0$. Conversely, $u_s(x) > 0$ only when $\|x - s\| < 2\operatorname{dist}(x, K)$.
[guided]
For each $s \in K$, we define the auxiliary function $u_s : U \to \mathbb{R}$ by
\begin{align*}
u_s(x) := \max\!\left\{2 - \frac{\|x - s\|}{\operatorname{dist}(x, K)},\; 0\right\}.
\end{align*}
The ratio $\|x - s\| / \operatorname{dist}(x, K)$ compares how far $x$ is from the specific point $s$ to how far $x$ is from $K$ as a whole. When this ratio is less than $2$, the point $s$ is "relatively close" among points of $K$, and the bump activates. When the ratio is $2$ or larger, the $\max$ with $0$ forces $u_s(x) = 0$, so $u_s$ has localised support.
**Continuity on $U$.** Both $x \mapsto \|x - s\|$ and $x \mapsto \operatorname{dist}(x, K)$ are continuous on $\mathbb{R}^n$. Since $\operatorname{dist}(x, K) > 0$ on $U$ (because $K$ is closed and $x \notin K$), the ratio $\|x - s\| / \operatorname{dist}(x, K)$ is continuous on $U$, and taking the maximum with $0$ preserves continuity.
**Bounded range: $0 \leq u_s(x) \leq 1$.** By definition, $\operatorname{dist}(x, K) = \inf_{y \in K} \|x - y\|$, and since $s \in K$, we have $\|x - s\| \geq \operatorname{dist}(x, K)$. Dividing both sides by $\operatorname{dist}(x, K) > 0$ gives $\|x - s\| / \operatorname{dist}(x, K) \geq 1$, hence $2 - \|x - s\| / \operatorname{dist}(x, K) \leq 1$. The $\max$ with $0$ ensures $u_s(x) \geq 0$, so $0 \leq u_s(x) \leq 1$.
**Localised support.** If $\|x - s\| \geq 2\operatorname{dist}(x, K)$, then $\|x - s\| / \operatorname{dist}(x, K) \geq 2$, so $2 - \|x - s\| / \operatorname{dist}(x, K) \leq 0$ and $u_s(x) = 0$. Conversely, $u_s(x) > 0$ only when $\|x - s\| < 2\operatorname{dist}(x, K)$.
Why is localised support essential? When we later verify continuity at a boundary point $a \in K$, we need to guarantee that only those partition functions corresponding to $s_k$ near $a$ contribute to the sum defining $\bar{f}(x)$. Localised support is what forces $v_k(x) = 0$ whenever $s_k$ is too far from $x$ relative to $\operatorname{dist}(x, K)$, ensuring that as $x \to a$, only values $f(s_k)$ with $s_k$ close to $a$ enter the weighted average.
[/guided]
[/step]
[step:Build a partition of unity on $U$ via a countable dense subset of $K$]
Since $K \subset \mathbb{R}^n$ is compact, it is separable. Choose a countable [dense subset](/page/Dense%20Subset) $\{s_k\}_{k=1}^\infty \subset K$ and define the normalising function
\begin{align*}
\sigma : U &\to \mathbb{R} \\
x &\mapsto \sum_{k=1}^\infty 2^{-k}\, u_{s_k}(x).
\end{align*}
**Convergence and continuity.** Since $0 \leq u_{s_k}(x) \leq 1$ for all $k$ and $x \in U$, we have $|2^{-k} u_{s_k}(x)| \leq 2^{-k}$ and $\sum_{k=1}^\infty 2^{-k} < \infty$. By the [Weierstrass M-Test](/theorems/261), the series converges uniformly on $U$. Each partial sum is continuous on $U$ (as a finite sum of continuous functions), so [uniform convergence](/page/Uniform%20Convergence) of the series to $\sigma$ implies $\sigma$ is continuous on $U$.
**Strict positivity.** Fix $x \in U$. We must show $\sigma(x) > 0$. Choose $y_0 \in K$ achieving $\|x - y_0\| = \operatorname{dist}(x, K)$; the infimum is attained because $K$ is compact and the distance function is continuous. By density of $\{s_k\}$ in $K$, there exists $s_{k_0}$ with $\|s_{k_0} - y_0\| < \frac{1}{2}\operatorname{dist}(x, K)$. By the triangle inequality,
\begin{align*}
\|x - s_{k_0}\| \leq \|x - y_0\| + \|y_0 - s_{k_0}\| < \operatorname{dist}(x, K) + \tfrac{1}{2}\operatorname{dist}(x, K) = \tfrac{3}{2}\operatorname{dist}(x, K).
\end{align*}
Since $\tfrac{3}{2} < 2$, property (iii) of the bump functions gives $u_{s_{k_0}}(x) \geq 2 - \tfrac{3}{2} = \tfrac{1}{2} > 0$. Therefore
\begin{align*}
\sigma(x) \geq 2^{-k_0}\, u_{s_{k_0}}(x) \geq 2^{-(k_0 + 1)} > 0.
\end{align*}
**[Partition of unity](/page/Partition%20of%20Unity).** Since $\sigma(x) > 0$ on $U$ and $\sigma$ is continuous, we define
\begin{align*}
v_k : U &\to \mathbb{R} \\
x &\mapsto \frac{2^{-k}\, u_{s_k}(x)}{\sigma(x)}, \qquad k \geq 1.
\end{align*}
Each $v_k$ is continuous on $U$, $v_k \geq 0$, and
\begin{align*}
\sum_{k=1}^\infty v_k(x) = \frac{1}{\sigma(x)} \sum_{k=1}^\infty 2^{-k}\, u_{s_k}(x) = \frac{\sigma(x)}{\sigma(x)} = 1 \qquad (x \in U).
\end{align*}
[guided]
Since $K \subset \mathbb{R}^n$ is compact, it is separable, so we may choose a countable dense subset $\{s_k\}_{k=1}^\infty \subset K$. Define the normalising function $\sigma : U \to \mathbb{R}$ by
\begin{align*}
\sigma(x) := \sum_{k=1}^\infty 2^{-k}\, u_{s_k}(x).
\end{align*}
The geometric weights $2^{-k}$ serve two purposes: they guarantee absolute convergence of the series (enabling the [Weierstrass M-Test](/theorems/261)), and they ensure that $\sigma$ is continuous as a uniform limit of continuous partial sums.
**Convergence and continuity of $\sigma$.** Since $0 \leq u_{s_k}(x) \leq 1$ for all $k$ and $x \in U$ (by the bounded range property), we have $|2^{-k} u_{s_k}(x)| \leq M_k := 2^{-k}$ for all $x \in U$, and $\sum_{k=1}^\infty M_k = 1 < \infty$. By the [Weierstrass M-Test](/theorems/261), the series $\sum_k 2^{-k} u_{s_k}$ converges uniformly on $U$. Each partial sum $\sum_{k=1}^N 2^{-k} u_{s_k}$ is continuous on $U$ (as a finite sum of continuous functions), so [uniform convergence](/page/Uniform%20Convergence) of the series to $\sigma$ implies $\sigma$ is continuous on $U$.
**Strict positivity of $\sigma$.** Fix $x \in U$. Choose $y_0 \in K$ with $\|x - y_0\| = \operatorname{dist}(x, K)$; the infimum is attained because $K$ is compact and the distance function is continuous. By density of $\{s_k\}$ in $K$, there exists $s_{k_0}$ with $\|s_{k_0} - y_0\| < \frac{1}{2}\operatorname{dist}(x, K)$. The triangle inequality gives
\begin{align*}
\|x - s_{k_0}\| \leq \|x - y_0\| + \|y_0 - s_{k_0}\| < \operatorname{dist}(x, K) + \tfrac{1}{2}\operatorname{dist}(x, K) = \tfrac{3}{2}\operatorname{dist}(x, K).
\end{align*}
Since $\tfrac{3}{2} < 2$, the localised support property gives $u_{s_{k_0}}(x) = 2 - \|x - s_{k_0}\|/\operatorname{dist}(x,K) \geq 2 - \tfrac{3}{2} = \tfrac{1}{2} > 0$. Therefore $\sigma(x) \geq 2^{-k_0} u_{s_{k_0}}(x) \geq 2^{-(k_0+1)} > 0$. Without density, there could be points $x \in U$ for which every $s_k$ satisfies $\|x - s_k\| \geq 2\operatorname{dist}(x,K)$, making all bumps vanish and $\sigma(x) = 0$.
**Partition of unity.** Since $\sigma(x) > 0$ on $U$ and $\sigma$ is continuous, we define $v_k : U \to \mathbb{R}$ by $v_k(x) := 2^{-k} u_{s_k}(x) / \sigma(x)$ for $k \geq 1$. Each $v_k$ is continuous on $U$, $v_k \geq 0$, and
\begin{align*}
\sum_{k=1}^\infty v_k(x) = \frac{1}{\sigma(x)} \sum_{k=1}^\infty 2^{-k}\, u_{s_k}(x) = \frac{\sigma(x)}{\sigma(x)} = 1 \qquad (x \in U).
\end{align*}
Thus $\{v_k\}_{k=1}^\infty$ is a partition of unity on $U$ subordinate to the dense subset $\{s_k\}$ of $K$. The normalisation by $\sigma$ converts the un-normalised bumps $2^{-k} u_{s_k}$ into weights that sum to $1$, which is what allows the extension $\bar{f}(x) = \sum_k v_k(x) f(s_k)$ to be expressed as a convex combination of values of $f$.
[/guided]
[/step]
[step:Define the extension and verify continuity on $U$]
Define the extension
\begin{align*}
\bar{f} : \mathbb{R}^n &\to \mathbb{R} \\
x &\mapsto \begin{cases} f(x), & x \in K, \\ \displaystyle\sum_{k=1}^\infty v_k(x)\, f(s_k), & x \in U. \end{cases}
\end{align*}
We verify that $\bar{f}$ is continuous on $U$. Let $E \subset U$ be an arbitrary compact subset. Since $E$ is compact and $\sigma$ is continuous with $\sigma > 0$ on $U$, we have
\begin{align*}
\alpha := \min_{x \in E} \sigma(x) > 0.
\end{align*}
Since $f$ is continuous on the compact set $K$, it is bounded: set $M := \sup_{y \in K} |f(y)| < \infty$. For each $k \geq 1$ and each $x \in E$,
\begin{align*}
|v_k(x)\, f(s_k)| = \frac{2^{-k}\, u_{s_k}(x)}{\sigma(x)}\, |f(s_k)| \leq \frac{2^{-k} \cdot 1}{\alpha} \cdot M = \frac{M}{\alpha}\, 2^{-k}.
\end{align*}
Since $\sum_{k=1}^\infty \frac{M}{\alpha}\, 2^{-k} = \frac{M}{\alpha} < \infty$, the [Weierstrass M-Test](/theorems/261) implies that the series $\sum_k v_k(\cdot)\, f(s_k)$ converges uniformly on $E$. Each partial sum $\sum_{k=1}^N v_k(x) f(s_k)$ is continuous on $U$ (as a finite sum of products of continuous functions), so the uniform limit $\bar{f}|_U$ is continuous on $E$. Since $E$ was an arbitrary compact subset of the open set $U$, the function $\bar{f}$ is continuous on $U$.
[guided]
We need to show that $\bar{f}$ is continuous on the open set $U = \mathbb{R}^n \setminus K$. Since continuity is a local property, it suffices to show that $\bar{f}$ is continuous on every compact subset $E \subset U$.
Fix an arbitrary compact set $E \subset U$. The normalising function $\sigma$ is continuous and strictly positive on $U$, so on the compact set $E$ it attains a positive minimum:
\begin{align*}
\alpha := \min_{x \in E} \sigma(x) > 0.
\end{align*}
Why does $\alpha > 0$? Because $\sigma$ is continuous on $U$ with $\sigma > 0$ everywhere on $U$, and $E \subset U$ is compact, so the continuous function $\sigma$ attains its infimum on $E$, which must be positive.
Since $f$ is continuous on the compact set $K$, it is bounded: define $M := \sup_{y \in K} |f(y)| < \infty$. For each $k \geq 1$ and $x \in E$, we bound the $k$-th term of the series:
\begin{align*}
|v_k(x)\, f(s_k)| = \frac{2^{-k}\, u_{s_k}(x)}{\sigma(x)}\, |f(s_k)| \leq \frac{2^{-k} \cdot 1}{\alpha} \cdot M = \frac{M}{\alpha}\, 2^{-k}.
\end{align*}
The bound $u_{s_k}(x) \leq 1$ comes from property (ii), $\sigma(x) \geq \alpha$ from the definition of $\alpha$, and $|f(s_k)| \leq M$ because $s_k \in K$.
Setting $M_k := (M/\alpha)\, 2^{-k}$, we have $\sum_{k=1}^\infty M_k = M/\alpha < \infty$. By the [Weierstrass M-Test](/theorems/261), the series $\sum_k v_k(\cdot)\, f(s_k)$ converges uniformly on $E$. Each partial sum $\sum_{k=1}^N v_k(x) f(s_k)$ is continuous on $U$ (a finite sum of products of continuous functions), so the uniform limit $\bar{f}|_E$ is continuous on $E$.
Why can we not apply the Weierstrass M-Test on all of $U$ at once? Because $\alpha = \min_E \sigma$ depends on $E$. As $x$ approaches $K$, the normaliser $\sigma(x)$ can shrink toward $0$, so there is no uniform positive lower bound on $\sigma$ over the entirety of $U$. However, every point $x_0 \in U$ has a compact neighbourhood $E \subset U$ (since $U$ is open), and the argument above shows $\bar{f}$ is continuous on $E$, hence at $x_0$. Since $E$ was arbitrary, $\bar{f}$ is continuous on $U$.
The genuinely subtle continuity argument is at points of $K$, which is handled in the next step.
[/guided]
[/step]
[step:Verify continuity at boundary points $a \in K$ via uniform continuity]
This is the central estimate. Fix $a \in K$ and $\varepsilon > 0$. Since $K$ is compact and $f : K \to \mathbb{R}$ is continuous, $f$ is [uniformly continuous](/page/Uniform%20Continuity) on $K$. Choose $\delta_1 > 0$ such that
\begin{align*}
|f(s) - f(a)| < \frac{\varepsilon}{2} \qquad \text{whenever } s \in K \text{ and } \|s - a\| < \delta_1.
\end{align*}
Set $\delta := \delta_1 / 4$.
We show that $|\bar{f}(x) - f(a)| < \varepsilon$ whenever $\|x - a\| < \delta$, which establishes continuity at $a$.
**Case 1: $x \in K$.** Then $\bar{f}(x) = f(x)$ and $\|x - a\| < \delta < \delta_1$, so $|\bar{f}(x) - f(a)| = |f(x) - f(a)| < \varepsilon/2 < \varepsilon$.
**Case 2: $x \in U$ with $\|x - a\| < \delta$.** We claim that every index $k$ with $v_k(x) > 0$ satisfies $\|s_k - a\| < \delta_1$. Indeed, $v_k(x) > 0$ requires $u_{s_k}(x) > 0$, which by property (iii) of the bump functions means $\|x - s_k\| < 2\operatorname{dist}(x, K)$. Since $a \in K$, we have $\operatorname{dist}(x, K) \leq \|x - a\| < \delta = \delta_1/4$. By the triangle inequality,
\begin{align*}
\|s_k - a\| \leq \|s_k - x\| + \|x - a\| < 2\operatorname{dist}(x, K) + \|x - a\| \leq 2\|x - a\| + \|x - a\| = 3\|x - a\| < 3\delta = \frac{3\delta_1}{4} < \delta_1.
\end{align*}
Therefore every $s_k$ that contributes to the sum satisfies $\|s_k - a\| < \delta_1$, and hence $|f(s_k) - f(a)| < \varepsilon/2$. Using $\sum_k v_k(x) = 1$,
\begin{align*}
|\bar{f}(x) - f(a)| &= \left|\sum_{k=1}^\infty v_k(x)\, f(s_k) - f(a) \sum_{k=1}^\infty v_k(x)\right| \\
&= \left|\sum_{k=1}^\infty v_k(x)\bigl(f(s_k) - f(a)\bigr)\right| \\
&\leq \sum_{k=1}^\infty v_k(x)\, |f(s_k) - f(a)| \\
&= \sum_{\substack{k \geq 1 \\ v_k(x) > 0}} v_k(x)\, |f(s_k) - f(a)| \\
&< \sum_{\substack{k \geq 1 \\ v_k(x) > 0}} v_k(x) \cdot \frac{\varepsilon}{2} = \frac{\varepsilon}{2} < \varepsilon.
\end{align*}
Since both cases give $|\bar{f}(x) - f(a)| < \varepsilon$, we conclude $\bar{f}$ is continuous at $a$.
[guided]
This is the heart of the proof. Fix $a \in K$ and $\varepsilon > 0$. Since $K$ is compact and $f : K \to \mathbb{R}$ is continuous, $f$ is [uniformly continuous](/page/Uniform%20Continuity) on $K$: there exists $\delta_1 > 0$ such that $|f(s) - f(a)| < \varepsilon/2$ whenever $s \in K$ and $\|s - a\| < \delta_1$. Set $\delta := \delta_1/4$. We show $|\bar{f}(x) - f(a)| < \varepsilon$ for all $x$ with $\|x - a\| < \delta$.
**Case 1: $x \in K$.** Then $\bar{f}(x) = f(x)$ and $\|x - a\| < \delta < \delta_1$, so $|\bar{f}(x) - f(a)| = |f(x) - f(a)| < \varepsilon/2 < \varepsilon$.
**Case 2: $x \in U$ with $\|x - a\| < \delta$.** We claim every index $k$ with $v_k(x) > 0$ satisfies $\|s_k - a\| < \delta_1$. Indeed, $v_k(x) > 0$ requires $u_{s_k}(x) > 0$, which by the localised support property means $\|x - s_k\| < 2\operatorname{dist}(x, K)$. Since $a \in K$, we have $\operatorname{dist}(x, K) \leq \|x - a\| < \delta = \delta_1/4$. The triangle inequality gives
\begin{align*}
\|s_k - a\| \leq \|s_k - x\| + \|x - a\| < 2\operatorname{dist}(x, K) + \|x - a\| \leq 2\|x - a\| + \|x - a\| = 3\|x - a\| < 3\delta = \frac{3\delta_1}{4} < \delta_1.
\end{align*}
**Why $\delta_1/4$ and not $\delta_1/2$?** The triangle inequality produces the factor $3\|x - a\|$, so we need $3\delta < \delta_1$, i.e., $\delta < \delta_1/3$. The choice $\delta = \delta_1/4$ provides a clean margin ($3\delta = 3\delta_1/4 < \delta_1$). Any $\delta \leq \delta_1/3$ would work; $\delta_1/4$ is a conventional choice that avoids the boundary case.
**Why uniform continuity?** We need to control $|f(s_k) - f(a)|$ for all contributing $s_k$ simultaneously. Pointwise continuity of $f$ at each $s_k$ would give a different $\delta$ depending on $s_k$, but the set of contributing indices varies with $x$, so there is no single finite collection of points to work with. [Uniform continuity](/page/Uniform%20Continuity) gives a single $\delta_1$ that works for all pairs of points within distance $\delta_1$, which is what the partition-of-unity argument requires. Uniform continuity is guaranteed by compactness of $K$ and continuity of $f$.
Since every contributing $s_k$ satisfies $\|s_k - a\| < \delta_1$, we have $|f(s_k) - f(a)| < \varepsilon/2$. Using the partition-of-unity identity $\sum_k v_k(x) = 1$ to write $f(a) = f(a) \sum_k v_k(x)$, we compute
\begin{align*}
|\bar{f}(x) - f(a)| &= \left|\sum_{k=1}^\infty v_k(x)\bigl(f(s_k) - f(a)\bigr)\right| \leq \sum_{k=1}^\infty v_k(x)\,|f(s_k) - f(a)| = \sum_{\substack{k \geq 1 \\ v_k(x) > 0}} v_k(x)\,|f(s_k) - f(a)| < \sum_{\substack{k \geq 1 \\ v_k(x) > 0}} v_k(x) \cdot \frac{\varepsilon}{2} = \frac{\varepsilon}{2} < \varepsilon.
\end{align*}
The key mechanism is that the weights $v_k(x) \geq 0$ sum to $1$, so $\bar{f}(x) - f(a)$ is a convex combination of the errors $f(s_k) - f(a)$. A convex combination of numbers in $(-\varepsilon/2, \varepsilon/2)$ remains in $(-\varepsilon/2, \varepsilon/2)$. Since both cases give $|\bar{f}(x) - f(a)| < \varepsilon$, the function $\bar{f}$ is continuous at $a$.
[/guided]
[/step]
[step:Conclude global continuity and assemble the vector-valued case]
Combining the previous steps: $\bar{f}$ is continuous on the open set $U$ (from the Weierstrass M-Test argument) and continuous at every point of $K$ (from the uniform continuity argument). Since $\mathbb{R}^n = K \cup U$ and $\bar{f}$ is continuous at each point of $\mathbb{R}^n$, the function $\bar{f} : \mathbb{R}^n \to \mathbb{R}$ is continuous and satisfies $\bar{f}|_K = f$.
For the general case $m \geq 2$: applying the scalar construction to each component $f_i : K \to \mathbb{R}$ yields continuous extensions $\bar{f}_i : \mathbb{R}^n \to \mathbb{R}$, and the map $\bar{f} := (\bar{f}_1, \dots, \bar{f}_m) : \mathbb{R}^n \to \mathbb{R}^m$ is continuous with $\bar{f}|_K = f$, completing the proof.
[/step]