Is it true that if $f:X\rightarrow Y$ and $g:Y\rightarrow X$ such that $g\circ f=I\_X,~~f\circ g=I\_y$ then $f,g$ must be one-one and onto (i.e. bijective)?

**Claim.** Yes.

**Proof.** Since $g(f(x))=x \implies g\circ f$ is injective. As if $g\circ f(a)=g\circ f(c)\implies a=c.$
Now, if $f(x)=f(y)\implies g\circ f(x)=g\circ f(y)\implies x=y\implies f$ is injective.
Also, since $g$ is covering every element in $X$ ( just simply take $f(x)$ in $g$). Hence $g$ is surjective.

Similarly with $f(g(x))=x\implies f \text{ is surjective}, g \text{ is injective}$, which impiles $f,g$ are bijective functions and hence $|X|=|Y|$.

Can someone check it? I am not sure that the above is correct.