Consider the function f(x)=sin(x)
We could say f:R->R. The codomain of f is R because that's where the values of x are mapped to.
The range of f:X->Y, S, is defined as: for all elements y in Y, there exists x in X such that y=f(x). Basically, S=f(X).
In our example above, the range is [-1,1].
We have π mapped to 0, π/2 mapped to 1, etc.
Note that the range is dependent on the domain.
Edit: If you consider g:[0,π/2]->R, then the range of g(x)=sin(x) is [0,1].
If you consider h:R->C, the range of h(x)=sin(x) is still [-1,1]. The codomain being the complex numbers. Since the domain are reals, sin maps them to real values.