TITLE: Composition equals identity function
QUESTION [7 upvotes]: Let $A$ and $B$ be two sets and $f: A \to B$ and $g: B \to A$ two functions for which $g \circ f = \text{id}_A$. Prove $f$ is injective and $g$ is surjective. 

I have no idea how to solve this. I know with injectivity proofs you have to show that if $f(a) = f(b)$ then $a=b$ and you have something similar for surjectivity, but in this case I don't know how to apply it.

REPLY [7 votes]: $g$ is surjective: We must prove for every $a\in A$ there exists $b\in B$ so that $g(b)=a$. Let $b=f(a)$. Then $g(b)=g(f(a))=a$ as desired.
$f$ is injective: We must prove if $a,a'\in A$ so that $f(a)=f(a')$ then $a=a'$. Notice $a=g(f(a))=g(f(a'))=a'$ as desired.