Given two groups A and B and an injective homomorphism f: A → B. When does a homomorphism g: B → A exist with gf = id_{A} (but not necessarily fg = id_{B})?

If and only if $B$ is a semidirect product of $A$ and another group (the latter is normal). One direction is obvious, and another direction is easy: $B$ is a semidirect product of the image of $f$ and the kernel of $g$. 

