Countable and Uncountable Sets

Countable and uncountable sets sort infinite sets by size. A set is countable if it is finite or its elements can be listed as a first, second, third and so on, which means it has a bijection with the natural numbers ℕ. The integers and rational numbers are countable, but the real numbers are uncountable.

Before this lesson: Injective, Surjective and Bijective Functions and Proof by Contradiction

Comparing sizes with bijections

Two finite sets have the same size when you can pair their elements one to one with nothing left over. That pairing is a bijection, and the same idea defines size for infinite sets: A and B have the same cardinality, written |A| = |B|, when there is a bijection from A to B.

In this lesson ℕ = {1, 2, 3, …}. A set is countably infinite if it has a bijection with ℕ, so its elements can be listed without end and without repeats. A set is countable if it is finite or countably infinite, and uncountable otherwise. Some books use “countable” to mean only countably infinite.

A \text{ is countably infinite} \iff \exists \, f \colon \mathbb{N} \to A \text{ that is a bijection}

Infinite sets behave in surprising ways. The even numbers are a proper subset of ℕ, yet f(n) = 2n pairs them with ℕ perfectly, so both sets have the same size.

Rules for countable sets

FactWhy it holds
Every subset of a countable set is countableKeep the listed elements that belong to the subset, in the same order.
If A and B are countable, so is A ∪ BAlternate between the two lists, skipping repeats.
A union of countably many countable sets is countableList the sets as rows and read along diagonals.
If A and B are countable, so is A × BPlace the pairs in a grid and read along diagonals.
If there is an injective function A → ℕ, then A is countableA is the same size as a subset of ℕ.
If B is uncountable and B ⊆ C, then C is uncountableOtherwise B would be a subset of a countable set.

Cantor’s diagonal argument

  1. Assume, for contradiction, that the numbers in (0, 1) can be listed as r1, r2, r3, …, and write each one as a decimal.
  2. Build a new number x = 0.x1x2x3… one digit at a time: make digit i of x different from digit i of ri. Use only the digits 4 and 5, so x has just one decimal form.
  3. Then x is in (0, 1), but x ≠ ri for every i, because they differ in digit i.
  4. So x is missing from the list, which contradicts the assumption. No list can contain every real number in (0, 1).

The interval (0, 1) is a subset of ℝ, so ℝ is uncountable too. This is a proof by contradiction, and it shows that some infinite sets are strictly larger than ℕ.

Countable and uncountable sets examples

Example 1: The even numbers are countable

Show that the set E = {2, 4, 6, …} of positive even numbers is countably infinite.

f(n) = 2n

Define f: ℕ → E. Each output is a positive even number.

2a = 2b \iff a = b

Injective: divide both sides by 2.

n = \dfrac{m}{2} \in \mathbb{N}

Surjective: each even m ∈ E is 2 times a natural number, so m/2 ∈ ℕ.

f\left(\dfrac{m}{2}\right) = m

Check: 2 times m/2 is m.

Answer: f(n) = 2n is a bijection from ℕ to E, so E is countably infinite. The list is 2, 4, 6, 8, ….

Example 2: The integers are countable

List the integers so that each one appears exactly once, and give a formula for the nth term.

n1234567
f(n)01−12−23−3
f(n) = \dfrac{n}{2} \text{ if } n \text{ is even}

Even positions hold the positive integers in order.

f(n) = -\dfrac{n - 1}{2} \text{ if } n \text{ is odd}

Odd positions hold 0, −1, −2, … in order.

f(1) = -\dfrac{0}{2} = 0,\ f(2) = \dfrac{2}{2} = 1,\ f(3) = -\dfrac{2}{2} = -1

Check the first three terms against the table.

k \gt 0:\ n = 2k;\quad k \le 0:\ n = 1 - 2k

Every integer k appears exactly once, at the position given here.

Answer: the list 0, 1, −1, 2, −2, 3, −3, … gives a bijection f: ℕ → ℤ, so ℤ is countably infinite. Listing 0, 1, 2, 3, … first would never reach the negative numbers.

Example 3: The positive rational numbers are countable

Arrange the fractions p/q in a grid and list them along the diagonals where p + q is constant, skipping fractions not in lowest terms. Find the first 9 terms, and find the position of 2/3.

A grid of fractions p over q with numerators 1 to 4 across the top and denominators 1 to 4 down the side. Numbered arrows follow the diagonals: 1/1 is 1st, 1/2 is 2nd, 2/1 is 3rd, 1/3 is 4th, 3/1 is 5th, 1/4 is 6th, 2/3 is 7th, 3/2 is 8th and 4/1 is 9th. The cells 2/2, 2/4, 3/3, 4/2 and 4/4 are gray and marked skip because they are not in lowest terms.
Reading the diagonals one at a time reaches every positive fraction after finitely many steps.
p + q = 2:\ \tfrac{1}{1}

The first diagonal has one fraction.

p + q = 3:\ \tfrac{1}{2},\ \tfrac{2}{1}

The second diagonal, in order of increasing p.

p + q = 4:\ \tfrac{1}{3},\ \tfrac{3}{1}

Skip 2/2, which equals 1/1 and is already listed.

p + q = 5:\ \tfrac{1}{4},\ \tfrac{2}{3},\ \tfrac{3}{2},\ \tfrac{4}{1}

All four are in lowest terms.

1 + 2 + 2 = 5

Count the terms before the p + q = 5 diagonal.

5 + 2 = 7

2/3 is 2nd on its diagonal, so it is 7th in the list.

Answer: the list begins 1, 1/2, 2, 1/3, 3, 1/4, 2/3, 3/2, 4, and 2/3 is the 7th term. Every positive fraction p/q sits on diagonal p + q, which is reached after finitely many steps, so the positive rationals are countable. Adding 0 and the negatives works as in Example 2, so ℚ is countable.

Example 4: A diagonal number that is not on the list

Suppose a list of numbers in (0, 1) begins with the four numbers below. Use Cantor’s rule (digit 5 if the diagonal digit is not 5, otherwise 4) to find the first four digits of a number x that differs from all four.

NumberDigit 1Digit 2Digit 3Digit 4
r1 = 0.1415…1415
r2 = 0.7182…7182
r3 = 0.5555…5555
r4 = 0.3333…3333
d_{11} = 1 \ne 5 \Rightarrow x_1 = 5

Digit 1 of r1 is 1, so use 5.

d_{22} = 1 \ne 5 \Rightarrow x_2 = 5

Digit 2 of r2 is 1, so use 5.

d_{33} = 5 \Rightarrow x_3 = 4

Digit 3 of r3 is 5, so use 4.

d_{44} = 3 \ne 5 \Rightarrow x_4 = 5

Digit 4 of r4 is 3, so use 5.

x = 0.5545\ldots

Combine the digits.

Answer: x = 0.5545…, which differs from r1 in digit 1, from r2 in digit 2, from r3 in digit 3 and from r4 in digit 4. Continuing forever gives a number in (0, 1) that differs from every number on the list.

Example 5: Hilbert’s hotel (word problem)

A hotel has rooms numbered 1, 2, 3, …, and every room is full. A bus arrives with infinitely many new guests, numbered 1, 2, 3, …. How can the hotel give everyone a room, one guest per room?

n \mapsto 2n

Move the guest in room n to room 2n. The old guests now fill the even rooms.

k \mapsto 2k - 1

Put new guest k in room 2k − 1. The new guests fill the odd rooms.

2n \ne 2k - 1

An even number never equals an odd number, so no two guests share a room.

m \text{ even} \Rightarrow \text{old guest } \tfrac{m}{2}

Every even room m gets an old guest.

m \text{ odd} \Rightarrow \text{new guest } \tfrac{m + 1}{2}

Every odd room m gets a new guest.

Answer: move each old guest from room n to room 2n and put new guest k in room 2k − 1. Every guest gets a room and every room is filled. This shows that the union of two countably infinite sets is still countably infinite.

Common mistakes

MistakeExample of the errorFix
Thinking a proper subset must be smaller“There are half as many even numbers as natural numbers.”f(n) = 2n is a bijection, so the two sets have the same cardinality.
Calling every infinite set uncountable“ℤ is infinite, so it is uncountable.”ℤ and ℚ are infinite but countable. Uncountable means no list exists at all.
Listing rationals row by row1/1, 1/2, 1/3, 1/4, …That list never reaches 2/1. Read along the diagonals instead.
Using the diagonal argument on ℚ“The diagonal number is missing, so ℚ is uncountable.”The diagonal number need not be rational, so it does not show a fraction is missing.
Using the digits 0 or 9 in the diagonalBuilding x = 0.4999…, which equals 0.5000…Use only 4 and 5, so x has one decimal form.
Thinking dense means uncountable“There is a fraction between any two fractions, so ℚ is uncountable.”Density is about order, not size. ℚ is dense and countable.

Related ideas

The real numbers are the rational and irrational numbers together. ℚ is countable and ℝ is not, so the irrational numbers must be uncountable: almost every real number is irrational. Cantor also proved that every set is strictly smaller than its power set, so 𝒫(ℕ) is uncountable, and there is no largest infinite size.

In computer science, there are only countably many programs, because each one is a finite string of characters. There are uncountably many functions from ℕ to {0, 1}, so some functions cannot be computed by any program.

Practice problems

  1. Show that the set of positive odd numbers {1, 3, 5, …} is countably infinite.
  2. Show that the set {10, 20, 30, …} is countably infinite.
  3. Using the list of integers from Example 2, find f(10) and f(11), and find the position n of −7.
  4. Continue the list of positive rationals from Example 3. What are the 10th and 11th terms?
  5. Is ℤ × ℤ countable? Explain.
  6. Is the set of irrational numbers countable? Explain.
  7. A list begins r1 = 0.2718…, r2 = 0.3550…, r3 = 0.6951… and r4 = 0.4145…. Use Cantor’s rule from Example 4 to find the first four digits of x.
  8. Is the set of all finite strings of 0s and 1s countable? How many strings have length at most 3?
  9. Hilbert’s hotel is full when 3 new guests arrive. How can everyone get a room?
  10. Prove that if B is uncountable and B ⊆ C, then C is uncountable.
Show answers

1.

f(n) = 2n - 1

Define f: ℕ → {1, 3, 5, …}.

2a - 1 = 2b - 1 \Rightarrow a = b

Injective: add 1 to both sides, then divide by 2.

n = \dfrac{m + 1}{2}

Surjective: for odd m, m + 1 is even, so this n is a natural number.

f\left(\dfrac{m + 1}{2}\right) = (m + 1) - 1 = m

Check the output.

Answer: f(n) = 2n − 1 is a bijection, so the positive odd numbers are countably infinite

2.

f(n) = 10n

Define f: ℕ → {10, 20, 30, …}.

10a = 10b \Rightarrow a = b

Injective: divide both sides by 10.

f\left(\dfrac{m}{10}\right) = m

Surjective: each m in the set is a multiple of 10, so m/10 ∈ ℕ.

Answer: f(n) = 10n is a bijection, so the set is countably infinite

3.

f(10) = \dfrac{10}{2} = 5

10 is even, so use n/2.

f(11) = -\dfrac{11 - 1}{2} = -5

11 is odd, so use −(n − 1)/2.

-\dfrac{n - 1}{2} = -7

−7 is negative, so n is odd.

n - 1 = 14

Multiply both sides by −2.

n = 15

Add 1 to both sides.

Answer: f(10) = 5, f(11) = −5, and −7 is in position 15

4.

p + q = 6:\ \tfrac{1}{5},\ \tfrac{2}{4},\ \tfrac{3}{3},\ \tfrac{4}{2},\ \tfrac{5}{1}

Write the next diagonal in order of increasing p.

\tfrac{1}{5},\ \tfrac{5}{1}

Skip 2/4, 3/3 and 4/2, which are not in lowest terms.

Answer: the 10th term is 1/5 and the 11th term is 5

5.

\mathbb{Z} \text{ is countable}

Example 2 lists the integers.

\mathbb{Z} \times \mathbb{Z} \text{ is countable}

A product of two countable sets is countable: place the pairs in a grid and read along diagonals.

Answer: yes, ℤ × ℤ is countably infinite

6.

\mathbb{R} = \mathbb{Q} \cup \mathbb{I}

Let 𝕀 be the set of irrational numbers. Every real number is rational or irrational.

\text{Assume } \mathbb{I} \text{ is countable}

Suppose, for contradiction, that 𝕀 is countable.

\mathbb{Q} \cup \mathbb{I} \text{ is countable}

A union of two countable sets is countable, and ℚ is countable.

\text{Contradiction}

That would make ℝ countable, but ℝ is uncountable.

Answer: no, the irrational numbers are uncountable

7.

d_{11} = 2 \Rightarrow x_1 = 5

Digit 1 of r1 is 2, not 5.

d_{22} = 5 \Rightarrow x_2 = 4

Digit 2 of r2 is 5.

d_{33} = 5 \Rightarrow x_3 = 4

Digit 3 of r3 is 5.

d_{44} = 5 \Rightarrow x_4 = 4

Digit 4 of r4 is 5.

Answer: x = 0.5444…

8.

\text{length } k: 2^k \text{ strings}

Each of the k positions is 0 or 1.

\bigcup_{k \ge 0} \{\text{strings of length } k\}

The set is a union of countably many finite sets, so it is countable: list the strings by length.

2^0 + 2^1 + 2^2 + 2^3 = 1 + 2 + 4 + 8

Count the strings of length 0, 1, 2 and 3.

= 15

Add.

Answer: yes, the set is countable, and 15 strings have length at most 3 (counting the empty string)

9.

n \mapsto n + 3

Move the guest in room n to room n + 3.

\{1, 2, 3\}

Rooms 1, 2 and 3 are now empty. Put the new guests there.

m \ge 4 \Rightarrow \text{old guest } m - 3

Every room from 4 up gets exactly one old guest.

Answer: move every guest up 3 rooms and put the new guests in rooms 1, 2 and 3

10.

\text{Assume } C \text{ is countable}

Suppose, for contradiction, that C is countable.

B \subseteq C \Rightarrow B \text{ is countable}

Every subset of a countable set is countable.

\text{Contradiction}

B was given as uncountable.

Answer: C must be uncountable

Countable and uncountable sets FAQ

What is the difference between countable and uncountable sets?

A countable set is finite or can be listed as a sequence with every element appearing at some position. An uncountable set is infinite and cannot be listed that way, because any list leaves elements out.

Are the rational numbers countable?

Yes. Listing the fractions p/q along the diagonals where p + q is constant reaches every rational number, so ℚ has the same cardinality as ℕ.

Why are the real numbers uncountable?

Cantor’s diagonal argument shows that any list of numbers in (0, 1) misses at least one number. Since no list can contain all of (0, 1), no list can contain all of ℝ.

Is a finite set countable?

Yes, under the usual definition, countable means finite or countably infinite. Some books use countable to mean countably infinite and say at most countable for both.

Summary

  • Two sets have the same cardinality when there is a bijection between them.
  • A set is countably infinite when it can be listed as a sequence with no repeats, and countable when it is finite or countably infinite.
  • ℕ, the even numbers, ℤ and ℚ are all countably infinite.
  • Cantor’s diagonal argument shows that (0, 1) and ℝ are uncountable.
  • Subsets, finite products and countable unions of countable sets are countable.

Previous lesson: Injective, Surjective and Bijective Functions

Next lesson: Divisibility and the Division Algorithm

Back to the Discrete Math Index