Surjective Function — Onto Function, Proof, Examples

#Algebra
TL;DR
A surjective function, also called an onto function, is one where every element of the codomain is hit by at least one input — nothing in the target set is left out. This article covers the formal definition, how to prove a function is surjective, the difference from injective and bijective functions, the codomain-versus-range distinction, and six worked examples.
BT
Bhanzu TeamLast updated on June 10, 20269 min read

What Is a Surjective Function?

A surjective function $f: A \to B$ is one where every element of the codomain $B$ has at least one preimage in the domain $A$. Formally: for every $y \in B$, there exists at least one $x \in A$ such that $f(x) = y$. The everyday name is an onto function — the function maps onto all of $B$, not just part of it.

There's no uniqueness requirement. Two or more inputs are allowed to land on the same output; what's forbidden is leaving any output unreached. That's the mirror image of the one to one (injective) function, which forbids two inputs sharing an output but allows outputs to go unused.

The one-line test: a function is surjective exactly when its range equals its codomain. If the outputs you actually produce fill the entire target set, it's onto.

What Is the Difference Between Codomain and Range?

This single distinction settles most surjectivity questions, so it's worth pinning down.

  • Codomain — the set you declare as the target when you write $f: A \to B$. It's a choice.

  • Range (or image) — the set of outputs the function actually produces.

The range is always a subset of the codomain. Surjective means the two are equal. Consider $f(x) = x^2$ written as $f: \mathbb{R} \to \mathbb{R}$. The codomain is all real numbers, but the range is only $[0, \infty)$ — no negative number is ever an output. So it's not surjective. Rewrite the same formula as $f: \mathbb{R} \to [0, \infty)$ and now range equals codomain — it is surjective. Surjectivity depends on the declared codomain, not just the formula.

How Do You Prove a Function Is Surjective?

The standard proof works backwards from an arbitrary output:

  1. Take an arbitrary element $y$ in the codomain.

  2. Solve the equation $f(x) = y$ for $x$.

  3. Show that the solution $x$ actually lies in the domain.

If you can always find such an $x$, every output is reachable, and the function is onto.

Worked once: is $f(x) = 2x + 1$, with $f: \mathbb{R} \to \mathbb{R}$, surjective? Pick any real $y$ and solve $2x + 1 = y$:

$$x = \frac{y - 1}{2}.$$

For every real $y$, this $x$ is a real number — so it's in the domain. Every output is hit.

It is surjective. This solve-for-$x$ method is the backbone of every onto proof.

What Is the Difference Between Surjective, Injective, and Bijective?

These three describe how a function's inputs and outputs line up, and they get mixed up constantly.

Type

Rule

Outputs

Injective (one-to-one)

distinct inputs give distinct outputs

no output used twice; some may be unused

Surjective (onto)

every codomain element is hit

every output used; some may be hit twice

Bijective (both)

one-to-one and onto

perfect pairing — every output hit exactly once

A bijective function is the gold standard: both injective and surjective, so each output comes from exactly one input. Bijections are precisely the functions with a true two-way inverse, which links straight back to why injectivity governs inverses.

How Many Surjective Functions Are There? (The Counting Question)

A question the SERP and forums raise often: from a set of $m$ elements onto a set of $n$ elements, how many onto functions exist? The answer uses inclusion-exclusion:

$$\sum_{k=0}^{n} (-1)^k \binom{n}{k} (n - k)^m.$$

The idea: count all $n^m$ functions, then subtract the ones that miss at least one target, adding back the over-subtracted overlaps. For $m = 3$ inputs onto $n = 2$ outputs, the formula gives $2^3 - 2 \cdot 1^3 = 8 - 2 = 6$ surjective functions — the same $6$ you'd get by listing them. This counting result connects surjections to Stirling numbers of the second kind.

Examples of Surjective Function

The examples build from a finite-set check, through the most common codomain mistake, to proofs and the counting formula.

Example 1

Is $f = {(1, a), (2, b), (3, b)}$ from ${1, 2, 3}$ to ${a, b}$ surjective?

Check the codomain ${a, b}$. Is $a$ hit? Yes, by $1$. Is $b$ hit? Yes, by $2$ and $3$. Every codomain element has at least one preimage.

Final answer: yes, it's surjective. The fact that $b$ is hit twice doesn't matter — surjectivity only cares that nothing is missed.

Example 2

A common slip — is $f(x) = x^2$, written $f: \mathbb{R} \to \mathbb{R}$, surjective?

Wrong attempt. A student reasons: "$x^2$ produces every non-negative number, and you can square-root any output to find an input, so every value is reachable — it's surjective."

Test it against a specific output. Is there a real $x$ with $f(x) = -4$? That needs $x^2 = -4$, which has no real solution. So the output $-4$, which sits in the declared codomain $\mathbb{R}$, is never produced.

Correct. The range is $[0, \infty)$, but the codomain is all of $\mathbb{R}$. Range $\neq$ codomain.

Final answer: no, $f: \mathbb{R} \to \mathbb{R}$ with $f(x) = x^2$ is not surjective. The negative reals in the codomain are never reached.

Example 3

Is $f(x) = x^3$, with $f: \mathbb{R} \to \mathbb{R}$, surjective?

Take any real $y$ and solve $x^3 = y$: the cube root $x = \sqrt[3]{y}$ is a real number for every $y$, positive, negative, or zero.

Final answer: yes, it's surjective — and since cubing is also one-to-one, it's bijective.

Example 4

Is $f(x) = 1 + x^2$, with $f: \mathbb{R} \to \mathbb{R}$, surjective?

The smallest value of $x^2$ is $0$, so the smallest output is $1$. The range is $[1, \infty)$, but the codomain is $\mathbb{R}$.

Final answer: no. No output is ever less than $1$, so every number below $1$ in the codomain is left out.

Example 5

Make $f(x) = x^2$ surjective by choosing the right codomain.

The formula's actual outputs fill $[0, \infty)$. Declare that set as the codomain: $f: \mathbb{R} \to [0, \infty)$. Now every target value $y \geq 0$ has a preimage $x = \sqrt{y}$.

Final answer: $f: \mathbb{R} \to [0, \infty)$ is surjective. Same formula, smarter codomain — surjectivity is a statement about the function and its declared target.

Example 6

Count the onto functions from a 3-element set to a 2-element set.

Use the inclusion-exclusion formula with $m = 3$, $n = 2$:

$$2^3 - \binom{2}{1}1^3 = 8 - 2 = 6.$$

Final answer: 6 surjective functions. The $2$ subtracted are the two functions that send all three inputs to a single output (missing the other), leaving $6$ that cover both targets.

Where Surjective Functions Earn Their Place

"Is every outcome actually reachable?"

The words surjection, injection, and bijection were coined by the French mathematical collective writing as Nicolas Bourbaki in the mid-20th century, who built much of modern mathematics on the precise language of sets and maps. "Onto" had been used informally for decades; Bourbaki gave it an exact, language-independent name so a proof would read identically in Paris, Tokyo, or São Paulo.

Where the idea does real work:

  • Coding and compression. A surjective encoding can produce every possible codeword — important when you need full coverage of an output space. Hash functions are deliberately surjective onto their output range so every bucket can be reached.

  • Counting and combinatorics. "How many ways can $n$ jobs be distributed so every worker gets at least one?" is an onto-function count — the Example 6 formula scaled up, the basis of many scheduling and partition problems.

  • Solving equations. Asking "does $f(x) = y$ always have a solution?" is asking whether $f$ is surjective onto the set of $y$ you care about. Existence of solutions is surjectivity in disguise.

Where Students Trip Up on Surjective Functions

Mistake 1: Ignoring the codomain

Where it slips in: Deciding surjectivity from the formula alone, without checking what codomain was declared.

Don't do this: Call $f(x) = x^2$ "surjective because it makes lots of outputs" without asking which set those outputs must fill.

The correct way: Compare range to codomain. Surjective means they're equal. The same formula can be onto with one declared codomain and not onto with another (Examples 2 and 5).

Mistake 2: Confusing surjective with injective

Where it slips in: Reading "every element is hit" and picturing the one-to-one rule instead.

Don't do this: Require that each output be hit exactly once. That's injective (and, combined with onto, bijective) — not surjective.

The correct way: Surjective only requires at least one preimage per output. Outputs hit twice are perfectly allowed. The second-guesser flips the two definitions under exam pressure; anchoring on "in-jective looks IN at uniqueness, sur-jective looks OUT at coverage" keeps them apart.

Mistake 3: Assuming a non-surjective function can't be made surjective

Where it slips in: Concluding a formula "isn't onto" and stopping there.

Don't do this: Treat surjectivity as a fixed property of the rule.

The correct way: Shrinking the codomain to match the range makes any function surjective (Example 5). Surjectivity is a property of the function together with its declared codomain.

Key Takeaways

  • A surjective function (onto function) reaches every element of its codomain: for every $y$ there's at least one $x$ with $f(x) = y$.

  • The one-line test is range $=$ codomain; the proof method is to solve $f(x) = y$ and show the solution lies in the domain.

  • Surjective differs from injective (uniqueness) and from bijective (both at once); only bijections have a two-way inverse.

  • The most common mistake is ignoring the codomain — the same formula can be onto or not depending on what target set is declared.

  • Onto functions underpin counting problems, hashing coverage, and the question of whether an equation always has a solution.

Where to Go From Here

  1. Decide whether $f(x) = 3x - 5$, with $f: \mathbb{R} \to \mathbb{R}$, is surjective, and prove your answer.

  2. Decide whether $f(x) = e^x$, with $f: \mathbb{R} \to \mathbb{R}$, is surjective.

  3. Count the onto functions from a 3-element set to a 3-element set.

Answer to Question 1: yes — solving $3x - 5 = y$ gives $x = (y+5)/3$, real for every $y$. Answer to Question 2: no — $e^x > 0$ always, so the range is $(0, \infty)$ and negative outputs are never reached. Answer to Question 3: $3! = 6$ (a surjection between equal-size finite sets is a bijection). If Question 2 came out "yes," return to Mistake 1 and check the codomain against the range.

Want a live Bhanzu trainer to walk through more surjective function problems? Book a free demo class — online globally.

Was this article helpful?

Your feedback helps us write better content

Frequently Asked Questions

Is a surjective function the same as an onto function?
Yes. "Surjective" and "onto" are two names for the same property — every element of the codomain has at least one input mapping to it.
What is the difference between injective and surjective?
Injective means no two inputs share an output (uniqueness); surjective means every output is reached (coverage). A function can be one, both, or neither.
Can a function be both injective and surjective?
Yes — such a function is called bijective. A bijection pairs each input with exactly one output and leaves nothing unreached, which is why it has a two-way inverse.
How do you prove a function is surjective?
Take an arbitrary $y$ in the codomain, solve $f(x) = y$ for $x$, and show that $x$ lies in the domain. If you can always do this, the function is onto. We worked an example in the proof section.
Does surjectivity depend on the codomain?
Yes, completely. The same formula can be surjective with one declared codomain and not surjective with another, because surjective means range equals codomain.
✍️ Written By
BT
Bhanzu Team
Content Creator and Editor
Bhanzu’s editorial team, known as Team Bhanzu, is made up of experienced educators, curriculum experts, content strategists, and fact-checkers dedicated to making math simple and engaging for learners worldwide. Every article and resource is carefully researched, thoughtfully structured, and rigorously reviewed to ensure accuracy, clarity, and real-world relevance. We understand that building strong math foundations can raise questions for students and parents alike. That’s why Team Bhanzu focuses on delivering practical insights, concept-driven explanations, and trustworthy guidance-empowering learners to develop confidence, speed, and a lifelong love for mathematics.
Related Articles
Book a FREE Demo ClassBook Now →