Example where values in codomain are not in image? I am familiar with the formal definitions of codomain (or output space) and image, but I would like to better understand what it means when $image(f)\ne Y$ for some function $f$ from $X$ to $Y$ where $f(x)=y$.
I know that $im(f)=Y$ if and only if the function is invertible. That is because if the function is not invertible, some information is "lost" when moving between the input space and the output space, so it is possible to have values that are part of the output space $Y$ that are not in the image of $f$. This makes sense to me, but I cannot seem to come up with a specific example of when or why that would happen. Can anyone please help? 
 A: The codomain is the space that we are considering the output to "live" in. If we are considering the outputs to be a certain type of number, and not all numbers of that type are a possible output, then the image and codomain are different (other terms for the image and codomain being the same are "onto" and "surjective", so you're looking for functions that aren't onto). For instance, suppose we take the rounding function, where $f(x)$ is $x$ rounded to the nearest integer. If we consider the output space to be the set of integers, then the function is onto. But if we consider the output space to be real numbers, then it's not onto. This is why, strictly speaking, to know whether a function is onto, we need to know not only what the rule for producing the output is, but also what the codomain is. Other examples of functions that don't map the reals onto the reals are $f(x)=x^2$ and $f(x)=e^x$; the former maps reals onto the nonnegative real numbers, and the latter maps reals onto positive reals.
For a function to be invertible, the inverse of every element must be well-defined. "well-defined" means that a value exists, and there is only one value (if there were more than one, it wouldn't be well-defined because we wouldn't know which is meant). The condition that for each $y$, there exists an $x$ such that $f(x) = y$ is this onto property. The condition that for every $y$, there is at most $x$ such that $f(x)=y$ is called "into", "one-to-one" or "injective". So being invertible is not equivalent to being onto; a function has to be both onto and into. An example of a function that is onto but not into is $f(x) = x^3-x = (x-1)x(x+1)$. This has three roots of $-1,0,1$, so it's not it's not into (there are three different values of $x$ that give $y=0$), but it is onto. You can also have functions that are into but not onto, such as $\arctan$.
You put the tag linear-algebra, so you may be thinking of the fact that square matrices are invertible if and only if their columns space is the whole space (i.e., onto). However, this is due to square matrices representing linear transformations between vectors spaces of the same dimension. If a linear transformation goes to a smaller space, it will not be invertible regardless of whether it's onto.
Whether a linear transformation is onto depends, again, on what one considers the output space to be. For instance, consider the transformation $P$ that projects a three dimensional vector to the $xy$-plane. If we look in three dimensional space, the image is a plane, which is a subset of $\mathbb{R}^3$, so it's not onto from that perspective. However, if we consider the codomain to be the $xy$-plane, then it is onto. When a linear transformation is represented by a matrix, the number of rows tells you what dimension the codomain is considered to have. If the rows are independent, then the transformation is onto this space.
A: The codomain of a function $f:X\to Y$ is simply a set which includes the image of the domain, i.e. $f(X)\subset Y$. This may seem redundant: why do not impose always $f(X)=Y$? This is because sometimes it is useful to consider a larger set: for example, it could be useful to consider the function $x\mapsto y=x^2$ as a member the class of functions $\{f:\mathbb{R}\to \mathbb{R}\}$ even if 
$$
x^2(\mathbb{R})=\mathbb{R}_+=\{x\in\mathbb{R}| x\ge 0\}.
$$ 
Another, more interesting example, is the one given by Mauro Allegranza in his comment: his example is nice because it alludes to the extension of a function from smaller domain and codomain to larger ones.
Finally, the condition you state for the equality
$$
\mathrm{image}(f)=Y
$$
to be true is not correct: the real "necessary and sufficient" condition is that $f$ should be surjective, i.e. for any $y\in Y$ there is (at least one) $x\in X$ such that $f(x)=y$. This condition is fulfilled if $f:X\to Y$ is invertible since in this case $f$ is both injective (i.e. $f(x_1)\neq f(x_2)$ if $x_1\neq x_2$) and sujective.
