Q:

If $|A|=30$ and $|B|=20$, find the number of surjective functions $f:A \to B$.

Let there be: $|A|=n$ and $|B|=m$  if $m>n$ then there are $$m(m-1)\cdots(m-n+1)$$ injective functions, so in this case  we have $|A|=30$ and  $|B|=20$ that means $m<n$ so there exists a surjective function, but I'm not sure if I can  find the number of surjective functions in the same way that I did find the number of injective functions.

A:

To construct a surjective function from $A$ to $B$, we want to distribute the elements of $A$ into $m$ bins (each representing an element of $B$) so that each bin contains at least one element. In other words, we want to partition the set $A$ consisting of $n$ elements into $m$ non-empty subsets, and assign an element of $B$ to each partition.
The number of ways to partition a set of $n$ elements into $m$ non-empty subsets is called the Stirling number of the second kind and usually denoted by
$$
\left\lbrace{n\atop m}\right\rbrace.
$$
There is no simple closed form for this number, but the wiki page contains a number of identities to calculate it, as well as a table for some values. In particular, we have
$$
\left\lbrace{30 \atop 20}\right\rbrace = 581535955088511150.
$$
For each partitioning of $A$, we can associate $m!$ surjective functions. Thus, the total number of surjective functions from $A$ to $B$ is
$$
\left\lbrace{30 \atop 20}\right\rbrace 20! = 1414819992961759105672223809536000000.
$$

