How many one to one and onto functions are there between two finite sets?

Not quite.

For the one-to-one function, each element in $X$ is mapped to a unique element in $Y$. Therefore, there are $M$ ways to map the first element in $X$, and $M-1$ ways to map the second one, etc. There should be totally $M!/(M-N)!$ ways of one-to-one mapping when $M\geq N$. When $M<N$, you cannot get any one-to-one mapping.

For the onto function, there seems to be no simple, non-recusive formula for the number of onto functions.

See Stirling number


Clearly if n < m there can be no onto functions from A to B, because under a function each element of A can map to only one element of B.

If n = m we have a bijection. The first element of A can map to any of the m elements of B. The second element of A can map to any of the remaining m - 1 elements of B, and so on. So the total number of onto functions is m!.

If n > m, there is no simple closed formula that describes the number of onto functions. We need to count the number of partitions of A into m blocks. For example, if n = 3 and m = 2, the partitions of elements a, b, and c of A into 2 blocks are: ab,c; ac,b; bc,a. Each of these partitions then describes a function from A to B. For example, the first partition -- ab,c -- says that a and b map to one element of B, and c maps to the other. Once we've counted the partitions we multiply by m!, just as in the bijection case, because for each partition the first block can map to any of the m elements of B, and so on.

The problem is that there is no simple, non-recursive way to calculate the number of partitions of an n-set into m blocks. These numbers are known as Stirling numbers of the second kind; see the reference below. See also sections 2.1.8 and 2.1.9 of the "Twelvefold Way" link.

So the best answer we can give for the case n ≥ m is: m! S(n,m), where S(n,m) is a Stirling number of the second kind.