Onto Function — Definition, Formula, Graph, and Examples

Book A Free Math Class

Onto Function — Definition, Formula, Graph, and Examples

TL;DR

An onto function (also called a surjective function) is one where every element of the codomain is the output of at least one input — nothing in the target set is left unreached. This article gives the formal definition, the test (range equals codomain), the formula for the number of onto functions, the onto-vs-into contrast, and six worked examples.

What Is An Onto Function?

An onto function f:A→B is one where every element of the codomain B is the image of at least one element of the domain A. Written formally: for every y∈B, there exists at least one x∈A such that f(x)=y. The textbook synonym is a surjective function — the map sends A onto all of B. The companion article on the surjective function walks the same idea through a formal onto-proof if you want the proof-heavy version.

There is no uniqueness condition. Two different inputs may land on the same output; the only thing forbidden is leaving an output unreached. The one-line working test is this:

A function is onto exactly when its range equals its codomain.

The range always sits inside the codomain. Onto means the two are the same set, with nothing left over.

How Do You Check If A Function Is Onto?

A common search is simply how do you know if a function is onto? The procedure runs backwards, starting from an arbitrary output:

  1. Take an arbitrary element y in the codomain B.
  2. Solve f(x)=y for x.
  3. Confirm that solution x actually lies in the domain A.

If you can always produce such an x, every output is reachable and the function is onto. On a graph, the parallel idea is the horizontal line test for onto: a function is onto its codomain when every horizontal line drawn through the codomain meets the graph at least once.

What Is The Difference Between An Onto Function And An Into Function?

The two terms are complements:

Every function is either onto or into — there is no third option once the codomain is fixed. The classic example is f(x)=x² written as f:R→R. No negative number is ever an output, so −4 has no preimage. The range is [0,∞), a proper subset of R, which makes the function into. The into function article works this contrast from the other side. Rewrite the codomain as f:R→[0,∞) and the same rule becomes onto.

What Is The Formula For The Number Of Onto Functions?

When A has m elements and B has n elements, the number of onto functions from A to B is counted by inclusion-exclusion:

Number of onto functions=∑k=0n(−1)k(nk)(n−k)m

A few consequences worth carrying:

Each symbol means: m is the size of the domain, n the size of the codomain, (nk) the number of ways to choose k codomain elements to exclude, and (n−k)m the number of functions mapping into the remaining n−k outputs.

Examples Of Onto Functions

Example 1

Decide whether f:{1,2,3}→{a,b} given by f(1)=a, f(2)=b, f(3)=b is onto.

Check each codomain element for an incoming arrow.

a is reached by 1.

b is reached by 2 and 3.

Both elements are reached, so the function is onto. The repeated output (b twice) is allowed.

Example 2

Decide whether f:R→R, f(x)=x², is onto.

The tempting first move is to say "every output has a square root, so it's onto."

Test it on a specific output. Pick y=−4 in the codomain R.

Solve x²=−4.

There is no real x whose square is −4.

So −4 is never produced. The function is not onto; its range is only [0,∞). Fix the codomain to [0,∞) and it becomes onto.

Example 3

Show that f:R→R, f(x)=2x−1, is onto.

Take an arbitrary y∈R.

Solve 2x−1=y.

x=y+1/2.

This x is a real number for every real y, so it lies in the domain.

Every output is reachable, so f is onto.

Example 4

Decide whether f:R→R, f(x)=x³, is onto.

Take an arbitrary y∈R.

Solve x³=y.

x=y³.

Every real number has a real cube root, so x is always in the domain.

The function is onto (and, since cubing is also one-one, it is bijective).

Example 5

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

Here m=3, n=2.

∑k=02(−1)k(2k)(2−k)³=8−2+0=6.

There are 6 onto functions.

Example 6

A factory has 4 machines, each routed to exactly one of 3 output bins. How many routings use every bin at least once?

This is "onto functions from a 4-element set to a 3-element set," so m=4, n=3.

∑k=03(−1)k(3k)(3−k)⁴=36.

So 36 routings leave no bin empty.

Why The Codomain Matters: "Onto Is A Claim About Coverage"

Onto exists because mathematics needed a precise way to say the map covers the whole target. That single idea decides whether a function can be reversed at all.

The destination this opens up is cardinality: comparing the sizes of infinite sets. The mathematician Georg Cantor used onto and one-one maps in the 1870s to prove that some infinities are genuinely larger than others.

Tripping Points To Avoid

Mistake 1: Confusing range with codomain

Where it slips in: any question where the function's formula produces fewer outputs than the declared target set.

Don't do this: declare f:R→R, f(x)=eˣ onto because "exponentials grow without bound."

The correct way: check the full codomain. eˣ is always positive, so 0 and every negative number are never outputs. Range is (0,∞), not R, so it is into, not onto.

Mistake 2: Treating a repeated output as a failure

Where it slips in: finite mapping diagrams where two inputs point at the same output.

Don't do this: call f(1)=a, f(2)=a, f(3)=b (codomain a,b) not-onto because "1 and 2 collide."

The correct way: collisions are irrelevant to onto-ness. Ask only whether every output is reached. Both a and b are reached, so it is onto.

Mistake 3: Forgetting that onto depends on the codomain

Where it slips in: problems that hand you a formula without naming the codomain.

Don't do this: answer "onto" or "not onto" before the target set is fixed.

The correct way: treat the codomain as part of the question. f(x)=x² is not onto as R→R but is onto as R→[0,∞). Same formula, opposite answer.

Conclusion