Injective, Surjective and Bijective Functions

Injective, surjective and bijective functions describe how a function f: A → B pairs inputs with outputs. An injective (one-to-one) function never sends two different inputs to the same output. A surjective (onto) function reaches every element of B. A bijective function does both, so it has an inverse.

Before this lesson: Relations and Functions, Inverse Functions and Power Sets and Cartesian Products

Domain, codomain and range

A function f: A → B assigns each element a of A exactly one element f(a) of B. The set A is the domain and B is the codomain. The range (or image) is the set of outputs that actually occur, and it can be smaller than the codomain.

f(A) = \{f(a) : a \in A\} \subseteq B

The codomain is part of the function. The rule f(x) = x² gives a different function on ℝ → ℝ than on [0, ∞) → [0, ∞), and the two can have different properties.

Definitions of injective, surjective and bijective

TypeDefinitionIn wordsArrow diagram test
Injective (one-to-one)f(a_1) = f(a_2) \implies a_1 = a_2different inputs give different outputsno output gets two arrows
Surjective (onto)\forall b \in B,\ \exists a \in A : f(a) = bevery element of B is an outputevery output gets at least one arrow
Bijectiveinjective and surjectiveeach element of B is the output of exactly one inputevery output gets exactly one arrow

The injective definition is often used in its contrapositive form: if a1 ≠ a2, then f(a1) ≠ f(a2). A function is surjective exactly when its range equals its codomain.

Four arrow diagrams. Injective, not surjective: 1, 2 and 3 go to a, b and d, and c gets no arrow. Surjective, not injective: 1 and 2 both go to a, 3 goes to b and 4 goes to c. Bijective: 1, 2 and 3 go to b, a and c, so each output gets exactly one arrow. Neither: 1 and 2 both go to a, 3 goes to c, and b gets no arrow.
Injective means no output gets two arrows. Surjective means every output gets at least one arrow.

How to prove a function is injective or surjective

  1. To prove f is injective, assume f(a1) = f(a2) and use algebra to show a1 = a2.
  2. To show f is not injective, give one pair of different inputs with the same output.
  3. To prove f is surjective, take an arbitrary b in the codomain, solve f(a) = b for a, check that a is in the domain, and check that f(a) = b.
  4. To show f is not surjective, give one element of the codomain that is never an output.

For finite sets, sizes give quick tests. If f: A → B is injective, then |A| ≤ |B|. If f is surjective, then |A| ≥ |B|. If f is bijective, then |A| = |B|. When A and B are finite with |A| = |B|, f is injective exactly when it is surjective.

A function has an inverse f−1: B → A exactly when it is bijective. Injective makes the inverse well defined, and surjective makes it defined on all of B. This is the set-based version of the horizontal line test in inverse functions.

Injective, surjective and bijective functions examples

Example 1: A function between finite sets

Let A = {1, 2, 3, 4} and B = {a, b, c}, and define f: A → B by f(1) = a, f(2) = c, f(3) = a and f(4) = b. Is f injective? Surjective? Bijective?

f(1) = f(3) = a

Look for an output with two arrows: 1 and 3 both go to a.

1 \ne 3

The inputs are different, so f is not injective.

f(A) = \{a, b, c\}

List the outputs: f(1) = a, f(2) = c, f(4) = b.

f(A) = B

The range equals the codomain, so f is surjective.

Answer: f is surjective but not injective, so it is not bijective. This matches the size test: |A| = 4 > 3 = |B|, so no function from A to B can be injective.

Example 2: Proving a linear function is a bijection

Prove that f: ℝ → ℝ, f(x) = 3x − 7, is bijective, and find its inverse.

3a - 7 = 3b - 7

Injective: assume f(a) = f(b) for real numbers a and b.

3a = 3b

Add 7 to both sides (see two-step equations).

a = b

Divide both sides by 3. So f is injective.

3x - 7 = y

Surjective: let y be any real number, and look for x with f(x) = y.

3x = y + 7

Add 7 to both sides.

x = \dfrac{y + 7}{3}

Divide both sides by 3. This x is a real number for every real y.

f\left(\dfrac{y + 7}{3}\right) = 3 \cdot \dfrac{y + 7}{3} - 7

Check: substitute this x into f.

= (y + 7) - 7

Cancel the factor of 3.

= y

Subtract 7. Every real y is an output, so f is surjective.

Answer: f is injective and surjective, so it is a bijection. Its inverse is f^{-1}(y) = \dfrac{y + 7}{3}.

Example 3: The domain and codomain matter

Is g(x) = x² injective or surjective as a function from ℝ to ℝ? What changes if the domain and codomain are both [0, ∞)?

g(-2) = (-2)^2 = 4

Test two inputs with opposite signs (see multiplying integers: a negative times a negative is positive).

g(2) = 2^2 = 4

−2 ≠ 2 but g(−2) = g(2), so g: ℝ → ℝ is not injective.

x^2 \ge 0 \text{ for every real } x

A square is never negative.

x^2 = -1 \text{ has no real solution}

So −1 is in the codomain but not in the range, and g: ℝ → ℝ is not surjective.

a^2 = b^2 \text{ with } a, b \ge 0

Now use g: [0, ∞) → [0, ∞). Injective: assume g(a) = g(b).

a = b

Take the nonnegative square root of both sides (see square roots); both a and b are nonnegative.

x = \sqrt{y} \in [0, \infty)

Surjective: for any y ≥ 0, this x is in the domain.

g(\sqrt{y}) = (\sqrt{y})^2 = y

Check that the output is y.

Answer: on ℝ → ℝ, g is neither injective nor surjective. On [0, ∞) → [0, ∞), the same rule is a bijection with inverse g^{-1}(y) = \sqrt{y}.

Example 4: A function on the integers

Let h: ℤ → ℤ, h(n) = 2n + 1. Show that h is injective but not surjective.

2a + 1 = 2b + 1

Injective: assume h(a) = h(b) for integers a and b.

2a = 2b

Subtract 1 from both sides.

a = b

Divide both sides by 2. So h is injective.

2n + 1 = 4

Not surjective: try the output 4.

2n = 3

Subtract 1 from both sides.

n = \tfrac{3}{2} \notin \mathbb{Z}

Divide both sides by 2. The only solution is not an integer, so 4 has no preimage.

Answer: h is injective but not surjective. Its range is the set of odd integers, which is smaller than the codomain ℤ. The same rule on ℝ → ℝ would be a bijection, which is another reason to state the domain.

Example 5: Student IDs and homerooms (word problem)

A school gives each of its 1,250 students an ID number from 1000 to 9999 and puts each student in one of 50 homerooms. Should the ID function be injective? Is it surjective? Can the homeroom function be injective, and when is it surjective?

9999 - 1000 + 1 = 9000

Count the possible IDs: 9999 − 1000 = 8999, and add 1 to include both ends.

\text{ID}(s_1) \ne \text{ID}(s_2) \text{ when } s_1 \ne s_2

Two students must never share an ID, so the ID function must be injective.

9000 - 1250 = 7750

Exactly 1,250 IDs are used, so 7,750 IDs are outputs of no student. The ID function is not surjective.

1250 \gt 50

The homeroom function sends 1,250 students to 50 homerooms. More inputs than outputs means two students share a homeroom, so it cannot be injective.

\text{every homeroom has a student}

The homeroom function is surjective exactly when no homeroom is empty.

Answer: the ID function is injective but not surjective. The homeroom function is never injective, and it is surjective when every homeroom has at least one student.

Common mistakes

MistakeExample of the errorFix
Testing the inputs instead of the outputs“Every input has one output, so f is injective.”That only says f is a function. Injective means no output comes from two inputs.
Ignoring the codomainSaying x² is onto because it covers [0, ∞)On ℝ → ℝ, −1 is never an output, so x² is not onto ℝ.
Proving injective with one examplef(1) ≠ f(2), so f is one-to-oneAssume f(a1) = f(a2) for arbitrary inputs and show a1 = a2.
Skipping the domain checkSolving 2n + 1 = 4 and calling h(n) = 2n + 1 onto ℤn = 3/2 is not an integer, so 4 has no preimage.
Mixing up range and codomainCalling the codomain of h the odd integersThe codomain is the set given in h: ℤ → ℤ. The range is the set of outputs.
Reversing the size testsSurjective, so |A| ≤ |B|Surjective needs |A| ≥ |B|; injective needs |A| ≤ |B|.

Related ideas

An isomorphism between two graphs is a bijection between their vertex sets that keeps every edge; see graph isomorphism.

Composing functions keeps these properties: if f and g are both injective, so is g ∘ f, and the same holds for surjective and bijective (see composition of functions). In linear algebra, a matrix map is one-to-one or onto under the same definitions, with tests based on pivots (see one-to-one and onto transformations).

Bijections are how mathematicians compare the sizes of sets: two sets have the same size exactly when there is a bijection between them. The next lesson, Countable and Uncountable Sets, uses this idea for infinite sets. The size test for injective functions is also the pigeonhole principle, which this course covers in the counting unit.

Practice problems

  1. Let A = {1, 2, 3} and B = {x, y, z}, with f(1) = y, f(2) = z and f(3) = x. Is f bijective? If so, find f−1.
  2. Let A = {1, 2, 3} and B = {p, q, r, s}, with f(1) = p, f(2) = r and f(3) = p. Is f injective? Is it surjective?
  3. Prove that f: ℝ → ℝ, f(x) = 5 − 2x, is bijective, and find its inverse.
  4. Is g: ℝ → ℝ, g(x) = |x|, injective? Is it surjective?
  5. Show that h: ℤ → ℤ, h(n) = n + 4, is a bijection, and find its inverse.
  6. Is k: ℤ → ℤ, k(n) = 3n, injective? Is it surjective?
  7. Is f: ℝ → [1, ∞), f(x) = x² + 1, injective? Is it surjective?
  8. A theater sells all 120 of its seats for one show, one ticket per seat, and no seat is sold twice. Explain why the function from tickets to seats is a bijection.
  9. Is f: ℤ → ℤ, f(n) = n², injective? Is it surjective?
  10. Prove that if f: A → B and g: B → C are both injective, then g ∘ f: A → C is injective.
Show answers

1.

f(A) = \{y, z, x\} = B

Every element of B is an output, so f is surjective.

\text{no output repeats}

y, z and x are all different, so f is injective.

f^{-1}(x) = 3,\ f^{-1}(y) = 1,\ f^{-1}(z) = 2

Reverse each arrow.

Answer: f is bijective, with f−1(x) = 3, f−1(y) = 1 and f−1(z) = 2

2.

f(1) = f(3) = p

Two different inputs share the output p, so f is not injective.

f(A) = \{p, r\} \ne B

q and s are never outputs, so f is not surjective.

Answer: f is neither injective nor surjective

3.

5 - 2a = 5 - 2b

Injective: assume f(a) = f(b).

-2a = -2b

Subtract 5 from both sides.

a = b

Divide both sides by −2. So f is injective.

5 - 2x = y

Surjective: let y be any real number.

-2x = y - 5

Subtract 5 from both sides.

x = \dfrac{5 - y}{2}

Divide both sides by −2. This x is real for every real y.

f\left(\dfrac{5 - y}{2}\right) = 5 - (5 - y) = y

Check: 2 times (5 − y)/2 is 5 − y, and 5 − (5 − y) = y.

Answer: f is bijective, with f−1(y) = (5 − y)/2

4.

g(-3) = g(3) = 3

−3 ≠ 3 but the outputs match, so g is not injective.

\vert x\vert \ge 0

An absolute value is never negative, so −1 is never an output.

Answer: g is neither injective nor surjective

5.

a + 4 = b + 4

Injective: assume h(a) = h(b).

a = b

Subtract 4 from both sides.

n = m - 4

Surjective: for any integer m, solve n + 4 = m by subtracting 4. n is an integer.

h(m - 4) = (m - 4) + 4 = m

Check the output.

Answer: h is a bijection, with h−1(m) = m − 4

6.

3a = 3b \implies a = b

Injective: divide both sides by 3.

3n = 1 \implies n = \tfrac{1}{3}

Try the output 1: divide both sides by 3.

\tfrac{1}{3} \notin \mathbb{Z}

The solution is not an integer, so 1 is never an output.

Answer: k is injective but not surjective (its range is the multiples of 3)

7.

f(-1) = f(1) = 2

Two different inputs give the same output, so f is not injective.

x^2 + 1 = y

Surjective: let y ≥ 1 be any element of the codomain.

x^2 = y - 1

Subtract 1 from both sides; y − 1 ≥ 0.

x = \sqrt{y - 1}

Take the square root; it is a real number because y − 1 ≥ 0.

f(\sqrt{y - 1}) = (y - 1) + 1 = y

Check the output.

Answer: f is surjective but not injective

8.

\text{no seat is sold twice}

Different tickets go to different seats, so the function is injective.

\vert \text{tickets}\vert = \vert \text{seats}\vert = 120

The two finite sets have the same size.

\text{injective} \implies \text{surjective}

For finite sets of equal size, injective and surjective go together, so every seat is sold.

Answer: the function is injective and surjective, so it is a bijection

9.

f(-1) = f(1) = 1

Two different inputs give the same output, so f is not injective.

1^2 = 1 \lt 2 \lt 4 = 2^2

Try the output 2: it lies strictly between two consecutive squares.

n^2 = 2 \text{ has no integer solution}

So 2 is never an output.

Answer: f is neither injective nor surjective

10.

g(f(a_1)) = g(f(a_2))

Assume (g ∘ f)(a1) = (g ∘ f)(a2) for a1, a2 in A.

f(a_1) = f(a_2)

g is injective, so its inputs f(a1) and f(a2) are equal.

a_1 = a_2

f is injective.

Answer: equal outputs of g ∘ f force equal inputs, so g ∘ f is injective

Injective, surjective and bijective functions FAQ

What is the difference between injective and surjective?

Injective means no two inputs share an output. Surjective means every element of the codomain is an output. A function can have either property, both or neither.

How do you prove a function is injective?

Assume f(a1) = f(a2) for arbitrary inputs and show that a1 = a2. To disprove it, find two different inputs with the same output.

Does every bijective function have an inverse?

Yes. A function f: A → B has an inverse f−1: B → A exactly when it is bijective, and the inverse is also a bijection.

Can a function be injective but not surjective?

Yes. h(n) = 2n + 1 from ℤ to ℤ is injective, but even numbers like 4 are never outputs. Whether a function is surjective depends on its codomain.

Summary

  • Injective (one-to-one): f(a1) = f(a2) implies a1 = a2.
  • Surjective (onto): every element of the codomain is an output, so the range equals the codomain.
  • Bijective: both, so every output comes from exactly one input and f has an inverse.
  • Prove injective by assuming equal outputs; prove surjective by solving f(a) = b and checking that a is in the domain.
  • For finite sets: injective needs |A| ≤ |B|, surjective needs |A| ≥ |B|, and bijective needs |A| = |B|.

Previous lesson: Power Sets and Cartesian Products

Next lesson: Countable and Uncountable Sets

Back to the Discrete Math Index