Surjection from Natural Numbers iff Countable

Theorem
Let $S$ be a set.

Then $S$ is countable iff there exists a surjection $f: \N \to S$.

Necessary Condition
Suppose that $f: \N \to S$ is a surjection.

By Surjection from Natural Numbers iff Right Inverse, $f$ admits a right inverse $g: \N \to S$.

We have that $g$ is an injection by Right Inverse Mapping is Injection.

Hence the result, by the definition of a countable set.

Sufficient Condition
Suppose that $S$ is countable.

Let $g: \N \to S$ be an injection.

Let $T \subseteq S$ be the image of $f$.

Let $\hat g: \N \to T$ be the restriction of $g$ to $\N \times T$.

We have that $\hat g$ is a bijection.

Let $\hat f$ be the inverse of $\hat g$.

From Bijection iff Inverse is Bijection, it follows that $\hat f: T \to \N$ is a bijection.

By the definition of a bijection, it follows that $\hat f$ is a surjection.

Define the mapping $f: S \to \N$ by:
 * $\displaystyle \forall x \in S: f \left({x}\right) =

\begin{cases} \hat f \left({x}\right) &: x \in T \\ 0 &: x \notin T \end{cases}$

Since $\hat f$ is a surjection, it follows that $f$ is a surjection.