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.
MV
Madhukar VLast updated on June 10, 20269 min read

What Is a Surjective Function?

A surjective function f:A→Bf: A \to B is one where every element of the codomain BB has at least one preimage in the domain AA. Formally: for every y∈By \in B, there exists at least one x∈Ax \in A such that f(x)=yf(x) = y. The everyday name is an onto function — the function maps onto all of BB, 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→Bf: 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)=x2f(x) = x^2 written as f:R→Rf: \mathbb{R} \to \mathbb{R}. The codomain is all real numbers, but the range is only [0,∞)[0, \infty) — no negative number is ever an output. So it's not surjective. Rewrite the same formula as f:R→[0,∞)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 yy in the codomain.

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

  3. Show that the solution xx actually lies in the domain.

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

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

x=y−12.x = \frac{y - 1}{2}.

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

It is surjective. This solve-for-xx 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 mm elements onto a set of nn elements, how many onto functions exist? The answer uses inclusion-exclusion:

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

The idea: count all nmn^m functions, then subtract the ones that miss at least one target, adding back the over-subtracted overlaps. For m=3m = 3 inputs onto n=2n = 2 outputs, the formula gives 23−2⋅13=8−2=62^3 - 2 \cdot 1^3 = 8 - 2 = 6 surjective functions — the same 66 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)f = {(1, a), (2, b), (3, b)} from 1,2,3{1, 2, 3} to a,b{a, b} surjective?

Check the codomain a,b{a, b}. Is aa hit? Yes, by 11. Is bb hit? Yes, by 22 and 33. Every codomain element has at least one preimage.

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

Example 2

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

Wrong attempt. A student reasons: "x2x^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 xx with f(x)=−4f(x) = -4? That needs x2=−4x^2 = -4, which has no real solution. So the output −4-4, which sits in the declared codomain R\mathbb{R}, is never produced.

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

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

Example 3

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

Take any real yy and solve x3=yx^3 = y: the cube root x=y3x = \sqrt[3]{y} is a real number for every yy, 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+x2f(x) = 1 + x^2, with f:R→Rf: \mathbb{R} \to \mathbb{R}, surjective?

The smallest value of x2x^2 is 00, so the smallest output is 11. The range is [1,∞)[1, \infty), but the codomain is R\mathbb{R}.

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

Example 5

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

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

Final answer: f:R→[0,∞)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=3m = 3, n=2n = 2:

23−(21)13=8−2=6.2^3 - \binom{2}{1}1^3 = 8 - 2 = 6.

Final answer: 6 surjective functions. The 22 subtracted are the two functions that send all three inputs to a single output (missing the other), leaving 66 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 nn 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)=yf(x) = y always have a solution?" is asking whether ff is surjective onto the set of yy 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)=x2f(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 yy there's at least one xx with f(x)=yf(x) = y.

  • The one-line test is range == codomain; the proof method is to solve f(x)=yf(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−5f(x) = 3x - 5, with f:R→Rf: \mathbb{R} \to \mathbb{R}, is surjective, and prove your answer.

  2. Decide whether f(x)=exf(x) = e^x, with f:R→Rf: \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=y3x - 5 = y gives x=(y+5)/3x = (y+5)/3, real for every yy. Answer to Question 2: no — ex>0e^x > 0 always, so the range is (0,∞)(0, \infty) and negative outputs are never reached. Answer to Question 3: 3!=63! = 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 yy in the codomain, solve f(x)=yf(x) = y for xx, and show that xx 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
Madhukar V
Madhukar V
Math Columnist & Analyst
I see mathematics as more than just numbers and formulas—it is a way of thinking, questioning, and understanding the world around us. I work at the intersection of mathematics, EdTech, technology, and AI-powered learning, I enjoy exploring how mathematical ideas can be made simple, meaningful, and relatable. Through my articles, I aim to present mathematics with curiosity and a practical perspective, helping readers see the beauty and relevance behind every concept in a Bhanzu way.
LinkedIn
Related Articles
Book a FREE Demo ClassBook Now →