To have an inverse, a function must be injective i.e one-one and it must be surjective i.e. onto.
Since if it is not surjective, the function's inverse's domain will have some elements left out which are not mapped to any element in the range of the function's inverse.