How can a continuous function map closed sets to open sets (and vice versa)? Definition of continuity: A function $f: X \to Y$ (where $X$ and $Y$ are topological spaces) is continuous if and only if for any open subset $V$ of $Y$, the preimage $f^{-1}(V)$ is open in $X$. 
Now, if $U$ is a closed subset of $X$ (meaning that the complement of $U$, $U^c$ is open and it contains all of its cluster points) and $f(U)$ (the image of $U$ under $f$) $= V$ is open in $Y$, then if $f$ is continuous, $f^{-1}(V) = f^{-1}(f(U)) = U$ is open. So if $U$ is closed then this leads to a contradiction. Conversely, if $U$ is open in $X$ and $f(U)=V$ is closed in $Y$, then $V^c$ is open. However, the complement of the preimage $f^{-1}(V)$ is closed since $(f^{-1}(V))^c = U$ which is open; which again leads to a contradiction. If there is anyone who has some valid counterexamples I'd be eager to see them.
 A: Your argument contains several errors. For example, suppose that $U$ is open in $X$ and $V=f[U]$ is closed in $Y$. It’s true that $Y\setminus V$ is open in $Y$ and hence that $f^{-1}[Y\setminus V]$ is open in $X$, but it’s not necessarily true that $f^{-1}[Y\setminus V]=X\setminus U$; consider what can happen when $f$ is not injective (one-to-one).
Let $X$ be a space with the discrete topology; then every subset of $X$ is both open and closed, so any function $f:X\to X$ is continuous and maps open sets to open sets, open sets to closed sets, closed sets to closed sets, and closed sets to open sets.
A: Any constant map $f : X \to \mathbb{R}$ is continuous and maps all subsets of $X$ (open, closed, both, or neither) to a closed subset of $\mathbb{R}$.
A: Let $X$ be your favorite topological space, perhaps $\mathbb{R}$, and $Y$ be the space with just a single point.Then the only function $f:X\to Y$ is continuous, and, just like with Brian M. Scott's example (indeed, $Y$ has the discrete topology here), every set maps to a set which is both open and closed.
