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: S \to \N$.

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: S \to \N$ be an injection.

Let $T \subseteq \N$ be the image of $g$.

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

By Restricting Injection to Bijection, $\hat g$ is a bijection.

Let $\hat f:T \to S$ be the inverse of $\hat g$.

By Inverse of Bijection is Bijection, $\hat f$ is also a bijection.

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

If $S$ has no elements, then the empty relation is a surjection from $\N$ onto $S$.

Suppose instead that $S$ has an element $x$.

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

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

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