I know that a function needs to be one-to-one so that it can have an inverse but could someone please explain why a function (in addition to being one-to-one) needs to be onto so that it can have inverse?
We define the function $f:A\rightarrow B$ as a rule that assigns for each $a\in A$, one specific member $f(a)\in B$. The range is denoted by $f(A)$ and is the set:
$$f(A)=\{f(x)|x\in A\}$$ Generally, $f(A)\subset B$ and if $f(A)\subseteq B$, then $f$ is said to be onto $B$.