Example: \(f(x) = x + 1\) and \(g(x) = \begin{cases} x - 1, & x > 1 \\ 1, & x = 1 \end{cases}\)
f is not onto: \(f(x) = x + 1 \ge 2\) for every \(x \in \mathbb{N}\), so \(1\) has no pre-image. Range of \(f\) is \(\{2, 3, 4, \dots\} \ne \mathbb{N}\).
gof is onto: for any \(x \in \mathbb{N}\), \(f(x) = x + 1 > 1\), so
\[(g\circ f)(x) = g(x + 1) = (x + 1) - 1 = x\]
Thus \(g\circ f\) is the identity function on \(\mathbb{N}\), which is onto: every \(y \in \mathbb{N}\) is the image of \(x = y\).
(Note that \(g\) is defined at \(x = 1\) separately only so that it maps \(\mathbb{N}\) into \(\mathbb{N}\); \(g\) itself is onto but not one-one.)