I have $2$ functions, $f:X\to Y$ and $g:Y\to X$. If $g\circ f=id_X$, where $id_X$ is the identity function on $X$, that is $id_X(x)=x$ for any $x\in X$, then I have to prove that $f$ is one-to-one and $g$ is onto.
The first part is simple. Let $x_1, x_2\in X$ such that $f(x_1)=f(x_2)$. Then $g(f(x_1))=g(f(x_2))$, so $x_1=x_2$.
I couldn't figure out how the prove the second fact. I tried to assume it's not onto, which means there exists an $x_1\in X$ such that for all $y\in Y$, $g(y)\neq x_1$. Since $f$ is one-to-one, this leads to $f(g(y))\neq f(x_1)$. I have no idea how to continue.