TITLE: How many surjections are there from a set of size n?
QUESTION [39 upvotes]: It is well-known that the number of surjections from a set of size n to a set of size m is quite a bit harder to calculate than the number of functions or the number of injections. (Of course, for surjections I assume that n is at least m and for injections that it is at most m.) It is also well-known that one can get a formula for the number of surjections using inclusion-exclusion, applied to the sets $X_1,...,X_m$, where for each $i$ the set $X_i$ is defined to be the set of functions that never take the value $i$. This gives rise to the following expression: $m^n-\binom m1(m-1)^n+\binom m2(m-2)^n-\binom m3(m-3)^n+\dots$.
Let us call this number $S(n,m)$. I'm wondering if anyone can tell me about the asymptotics of $S(n,m)$. A particular question I have is this: for (approximately) what value of $m$ is $S(n,m)$ maximized? It is a little exercise to check that there are more surjections to a set of size $n-1$ than there are to a set of size $n$. (To do it, one calculates $S(n,n-1)$ by exploiting the fact that every surjection must hit exactly one number twice and all the others once.) So the maximum is not attained at $m=1$ or $m=n$. 
I'm assuming this is known, but a search on the web just seems to lead me to the exact formula. A reference would be great. A proof, or proof sketch, would be even better.
Update. I should have said that my real reason for being interested in the value of m for which S(n,m) is maximized (to use the notation of this post) or m!S(n,m) is maximized (to use the more conventional notation where S(n,m) stands for a Stirling number of the second kind) is that what I care about is the rough size of the sum. The sum is big enough that I think I'm probably not too concerned about a factor of n, so I was prepared to estimate the sum as lying between the maximum and n times the maximum.

REPLY [2 votes]: Many people may be interested in the asymptotics for $n=cm$ where $c$ is constant (say $c=2$).
That is, how likely is a function from $2m$ to $m$ to be onto?
I couldn't dig the answer out from some of the sources and answers here, but here is a way that seems okay.
Bender (Central and local limit theorems applied to asymptotics enumeration) shows
$$\begin{eqnarray*}{n\brace m}&\sim&\frac{n!e^{-\alpha m}}{m!\rho^{n-1}(1+e^\alpha)\sigma\sqrt{2\pi n}},\\
\frac{n}m &=& (1+e^\alpha)\ln(1+e^{-\alpha}),\\
\rho&=&\ln(1+e^{-\alpha}),\\
\sigma^2&=&\left(\frac{m}n\right)^2[1-e^\alpha\ln(1+e^{-\alpha})].\end{eqnarray*}$$
Notice that for constant $n/m$, all of $\alpha$, $\rho$, $\sigma$ are constants.
For $c=2$, we find $\alpha=-1.366$
and then $\rho=1.59$
and $$\sigma^2=\frac14 [1-e^\alpha\ln(1+e^{-\alpha})]=\frac14 [1-e^{-1.366}(1.59)]=.149$$
Thus the probability that our function from $cm$ to $m$ is onto is
$$\Pr(\text{onto})=\frac1{m^n}m!{n\brace m}=\frac1{m^n}m!\frac{n!e^{-\alpha m}}{m!\rho^{n-1}(1+e^\alpha)\sigma\sqrt{2\pi n}}$$
$$=\frac1{m^n}\frac{n!e^{-\alpha m}}{\rho^{n-1}(1+e^\alpha)\sigma\sqrt{2\pi n}}$$
Does it go to 0? Well, $\rho=1.59$ and $e^{-\alpha}=3.92$, so up to polynomial factors we have
$$\frac1{m^n}\frac{n!e^{-\alpha m}}{\rho^{n}}\approx\frac{n!(3.92^m)}{(1.59)^n(n/2)^n}$$
$$\approx \frac{(3.92^m)}{e^{n}(1.59)^n(1/2)^n}=\left(\frac{2^2\times 3.92}{1.59^2\times e^2}\right)^m=0.839^m$$
So phew... it goes to 0, but not as fast as for the case $n=m$ which gives $(1/e)^m$.