# extending a continuous function from a closed subset

Is it true that a continuous function defined on a closed subset of $\mathbb{R^n}$ extends to a continuous function on the whole space?

If we don't have any restriction on the range of the continuous function, then the answer is no. Namely, let $A=\{0,1\}\subseteq\mathbb{R}$ and consider the continuous function $\operatorname{id}_A$. You can't extend $\operatorname{id}_A$ to a continuous function on the whole $\mathbb{R}$ because $\mathbb{R}$ is connected while $A$ is not.
However, if the range of the continuous function is for example $\mathbb{R}$, then the extension can always be done, see Tietze extension theorem.
• I don't follow your argument. $f:\mathbb{R} \to \mathbb{R}$ with $f(x)=0$ for $x \lt 0$, $f(x)=x$ for $x \in [0,1]$ and $f(x)=1$ for $x \gt 0$ seems to be continuous and agreeing with your function on $A$? Edit: Never mind me, you're discussing $A \to A$ - I implicitly assumed the function was into the reals. – Desiato Mar 19 '12 at 19:29