How many distinct functions can be defined from set A to B?

A function on a set involves running the function on every element of the set A, each one producing some result in the set B. So, for the first run, every element of A gets mapped to an element in B. The question becomes, how many different mappings, all using every element of the set A, can we come up with? Take this example, mapping a 2 element set A, to a 3 element set B. There are 9 different ways, all beginning with both 1 and 2, that result in some different combination of mappings over to B.

enter image description here

The number of functions from A to B is |B|^|A|, or $3^2$ = 9.


Let set $A$ have $a$ elements and set $B$ have $b$ elements. Each element in $A$ has $b$ choices to be mapped to. Each such choice gives you a unique function. Since each element has $b$ choices, the total number of functions from $A$ to $B$ is $$\underbrace{b \times b \times b \times \cdots b}_{a \text{ times}} = b^a$$


Let's say for concreteness that $A$ is the set $\{p,q,r,s,t,u\}$, and $B$ is a set with $8$ elements distinct from those of $A$. Let's try to define a function $f:A\to B$.

What is $f(p)$? It could be any element of $B$, so we have 8 choices.

What is $f(q)$? It could be any element of $B$, so we have 8 choices.

...

What is $f(u)$? It could be any element of $B$, so we have 8 choices.

So there are $8\cdot8\cdot8\cdot8\cdot8\cdot8 = 8^6$ ways to choose values for $f$, and each possible set of choices defines a different function $f$. So that's how many functions there are.