Logic, Sets and Infinity

Injective, Surjective and Bijective Functions Made Clear

Tell one-to-one, onto and two-way functions apart, prove which is which with worked examples, and avoid the usual domain traps.

Key takeaways

  • Injective means no two inputs share an output, so you can recover the input from the output.
  • Surjective means every element of the codomain is the output of at least one input.
  • Whether a formula is injective or surjective depends on the domain and codomain you choose, not on the formula alone.
  • A function has a two-sided inverse exactly when it is bijective.

A function is injective if different inputs always give different outputs, surjective if every element of the target is actually hit, and bijective if it is both. A bijection pairs up two sets perfectly, with nothing shared and nothing left over.

These three words sound technical, but each answers a simple question about arrows from one set to another. Once you can test them, you can decide when a function can be reversed and when two collections have the same size.

Domain, codomain and image

A function f from A to B, written f: A → B, assigns to each element of A exactly one element of B. A is the domain and B is the codomain. The image is the set of outputs that actually occur, which may be smaller than the codomain. If the idea is new, what a function is covers the background.

Picture two columns of dots with one arrow leaving each dot on the left. The function rule demands exactly one arrow out of every input. It says nothing about how many arrows arrive at each dot on the right. The three properties are about those arrivals.

Property Arrows arriving at each element of B Other names
Injective At most one One-to-one
Surjective At least one Onto
Bijective Exactly one One-to-one correspondence

The words injective, surjective and bijective were popularized by the group of mathematicians writing under the name Bourbaki. Be careful with "one-to-one function" (injective) and "one-to-one correspondence" (bijective), which look alike and mean different things.

Testing injectivity

The practical test is to assume two outputs are equal and show the inputs must be equal.

f is injective:  for all a, b in A,  f(a) = f(b)  implies  a = b

Take f(x) = 3x − 5 on the real numbers.

f(a) = f(b)
3a − 5 = 3b − 5
3a = 3b                 add 5 to both sides
a = b                   divide by 3

So f is injective. To show that a function is not injective, you only need one pair of different inputs with the same output. For g(x) = x² on the real numbers, g(−3) = g(3) = 9, so g is not injective. A single counterexample is enough.

On a graph, the horizontal line test says the same thing: if some horizontal line meets the graph twice, two inputs share an output. A function on an interval that is strictly increasing is injective, because larger inputs give larger outputs.

Testing surjectivity

Here you start with an arbitrary target and produce an input that reaches it.

f is surjective:  for every b in B there is some a in A with f(a) = b

For f(x) = 3x − 5, take any real y. Solve 3x − 5 = y to get x = (y + 5)/3, which is a real number. Check: 3 × (y + 5)/3 − 5 = y. So f is surjective, and therefore bijective.

The solving step is scratch work. The proof is the check that your proposed input lies in the domain and really produces y. That distinction matters when the domain is restricted. If f(x) = 3x − 5 goes from the integers to the integers, then y = 0 would require x = 5/3, which is not an integer. The same formula is now injective but not surjective.

One formula, four verdicts

The rule x² shows how much depends on the sets.

Function Injective? Surjective?
x² from all reals to all reals No No
x² from all reals to reals ≥ 0 No Yes
x² from reals ≥ 0 to all reals Yes No
x² from reals ≥ 0 to reals ≥ 0 Yes Yes

The first fails to be surjective because no real square equals −1. The last is a bijection, and its inverse is the square root function.

Familiar functions behave the same way. The exponential eˣ is injective from the reals to the reals and becomes bijective when the codomain is the positive reals, which is why the natural logarithm ln is defined on positive numbers. The sine function from the reals onto the interval [−1, 1] is surjective but repeats values. Restrict it to [−π/2, π/2], with angles in radians, and it becomes a bijection, which is how arcsine is defined.

A worked example that needs care

Consider h(x) = x/(x − 2), defined for every real x except 2. Is it injective, and which values does it reach?

Injectivity:
  a/(a − 2) = b/(b − 2)
  a(b − 2) = b(a − 2)       multiply by both denominators
  ab − 2a = ab − 2b
  a = b                     so h is injective

Reachable values: solve y = x/(x − 2)
  y(x − 2) = x
  yx − x = 2y
  x(y − 1) = 2y
  x = 2y/(y − 1)            needs y ≠ 1

No input gives y = 1, since that would require x = x − 2. So h is not surjective onto the reals. Take the codomain to be all reals except 1, and h becomes a bijection with inverse y → 2y/(y − 1). Check one value: h(4) = 4/2 = 2, and the inverse sends 2 back to 4/1 = 4.

Solving for the input did two jobs. It exposed the missing value and produced the inverse formula.

Inverses

An inverse of f: A → B is a function g: B → A with g(f(a)) = a for every a, and f(g(b)) = b for every b. Such a g exists exactly when f is a bijection.

The two conditions can also be taken separately.

  • If some g satisfies g(f(a)) = a for all a, then f is injective. Conversely, an injective f with nonempty domain has such a left inverse.
  • If some g satisfies f(g(b)) = b for all b, then f is surjective. The converse, that every surjection has such a right inverse, needs the axiom of choice in general.

To find the inverse of a bijection given by a formula, solve y = f(x) for x. For f(x) = 3x − 5, the inverse is g(y) = (y + 5)/3. A quick test: f(4) = 7 and g(7) = 4.

Composing functions

Composition, written g∘f, means apply f first and then g. The properties carry through in predictable ways.

  1. If f and g are both injective, so is g∘f.
  2. If f and g are both surjective, so is g∘f.
  3. If g∘f is injective, then f is injective, though g need not be.
  4. If g∘f is surjective, then g is surjective, though f need not be.

Here is the proof of the third. Suppose f(a) = f(b). Apply g to both sides to get g(f(a)) = g(f(b)). Since g∘f is injective, a = b.

For a case where the other function misbehaves, let f send the single element 1 to x, inside a codomain {x, y}, and let g send both x and y to the same element z in the set {z}. Then g∘f is a bijection from {1} to {z}. Yet f is not surjective and g is not injective.

Four kinds of function
Injective only No shared outputs, but some targets missed Surjective only All targets hit, some more than once Bijective Every target hit exactly once Neither Some targets missed and some shared Injective only No shared outputs, but some targets missed Surjective only All targets hit, some more than once Bijective Every target hit exactly once Neither Some targets missed and some shared

Counting with finite sets

For finite sets A and B, the properties restrict sizes. An injection from A to B forces |A| ≤ |B|, where |A| is the number of elements. A surjection forces |A| ≥ |B|. A bijection forces |A| = |B|.

The first statement, read backward, is the pigeonhole principle: put more pigeons than holes, and some hole gets two.

When |A| = |B| and both are finite, injective and surjective become equivalent. If five people sit in five chairs with no sharing, every chair is filled.

You can count functions too. From a 3-element set to a 5-element set there are 5³ = 125 functions. Of these, 5 × 4 × 3 = 60 are injective. From a 3-element set onto a 2-element set there are 2³ = 8 functions, of which 2 are constant, leaving 6 surjections.

Infinite sets behave differently

The finite equivalence breaks for infinite sets. On the natural numbers including 0, the map n → n + 1 is injective but misses 0. The map that sends n to n ÷ 2 rounded down is surjective but sends both 0 and 1 to 0.

This freedom is what lets an infinite set be matched with a proper part of itself, as with n → 2n onto the even numbers. Bijections are the official way to compare infinite sizes, described in proving two infinite sets have the same size.

Where the three properties show up

You meet these ideas well outside set theory.

An identification number system should be injective: two people must never receive the same number. It need not be surjective, since unused numbers are harmless.

A hash function, which turns data of any length into a fixed-length string, cannot be injective, because there are more possible inputs than outputs. Designers aim to make collisions hard to find in practice.

A substitution cipher that swaps each letter of an alphabet for another must be a bijection of the alphabet. If two letters shared a code, the reader could not decode the message. This is a teaching example only and gives no real security.

In linear algebra, a square matrix defines a map that is injective exactly when it is surjective, a fact that resembles the finite-set rule even though the spaces have infinitely many vectors. Finite dimension plays the role that finite size played above.

In each case the useful question is the same: can information be lost on the way through (a failure of injectivity), and can every target be produced (surjectivity)?

Mistakes to watch for

  • Confusing the function rule with injectivity. "Each input has one output" is required of every function. Injectivity is about each output having at most one input.
  • Proving the converse. Showing that a = b implies f(a) = f(b) proves nothing, since it holds for any function.
  • Forgetting the codomain. "Is x² surjective?" has no answer until the sets are stated.
  • Checking a few values. Testing f(1), f(2) and f(3) can suggest a property but cannot prove it for an infinite domain.
How to classify a function
1 Name the sets Write down domain and codomain 2 Test injective Set outputs equal and solve for inputs 3 Test surjective Take any target and build an input 4 Conclude Both pass means an inverse exists Name the sets Write down domain and codomain 1 Test injective Set outputs equal and solve for inputs 2 Test surjective Take any target and build an input 3 Conclude Both pass means an inverse exists 4

Written for 4Mathematics with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 41 articles in Logic, Sets and Infinity →

Latest news on this topic