Say that $\Bbb N \times \Bbb N$ is the set of all pairs $(n_1, n_2)$ of natural numbers. Is it countable? My hypothesis is yes it is countable because sets are countable. But I am unable to come up with a proof. Is my hypothesis correct? How is it countable?


marked as duplicate by Martin R, draks ..., Najib Idrissi, Martin Sleziak, Chris Culter May 22 '15 at 8:57

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Consider the function $f: \mathbb{N} \times \mathbb{N} \longrightarrow \mathbb{N}$ defined by $f(a,b)=2^a \, 3^b$. Then this function is one-one. Consequently cardinality of $\mathbb{N} \times \mathbb{N}$ is "no more than" (if I may use this phrase) that of $\mathbb{N}$, hence countable.

  • $\begingroup$ Could you explain "cardinality of N×N is "no more than" (if I may use this phrase) that of N" a little bit more. I am not quite understand what you mean by that? $\endgroup$ – Rajesh May 22 '15 at 19:06
  • 1
    $\begingroup$ @Rajesh Suppose $f: A \longrightarrow B$ is an injective function. We know that image of $A$ under $f$ will be a subset of $B$. Thus $|f(A)| \leq |B|$. However by injectivity we also know that $|A|=|f(A)|$ hence $|A| \leq |B|$. The reason I used the phrase "if I may say" is because we are dealing with cardinal numbers so less than or equal to should be dealt with carefully unlike finite numbers. For more see en.wikipedia.org/wiki/Cardinality $\endgroup$ – Anurag A May 22 '15 at 21:24

First, list the pairs in which the sum is $0$:


Then those in which the sum is $1$:


Then those in which the sum is $2$:


Then those in which the sum is $3$:


And so on.


Yes, you do the diagonalization like with rational numbers which is basically the same thing.


Yes, here is a bijection example, where $p_k$ is the $kth$ prime number:

  • $f(x,y)=p_x^{p_y}$

  • $g(x)=(x,x)$


Another easy way :take a pair, write down the numbers in any numeration basis. For example (decimal) 1234 and 987. Add extra zeros where needed so they are the same length, and shuffle them

1 2 3 4
 0 9 8 7

Reverse operation : take digits with even (resp. odd) positions.

EDIT: and of course there are explicit formulas, here given as 3 recursive Python functions

def combine(a,b):
   return 0 if a==0 and b==0 else 10*combine(b/10, a) + (b % 10)
def second(n):
   return 0 if n==0 else 10*second(n/100)+ (n%10)
def first(n):
   return second(n/10)

Here is an explicit formula for a bijection with $\mathbf N$, using the ordering first by ‘total degree’, then by first coordinate (known as grlex order on $\mathbf N\times\mathbf N$):



Not the answer you're looking for? Browse other questions tagged or ask your own question.