TITLE: How many one to one and onto functions are there between two finite sets?
QUESTION [9 upvotes]: Suppose $X$ has $N$ elements and $Y$ has $M$ elements. How many one to one function are there from $X$ to $Y$? How many onto function are there from $X$ to $Y$?

The number of one to one functions is $N!$,
  because the max mapping to $Y$ is $N$.
The number of onto functions is $M^N - M + M((M-1)^N-(M-1))$,
  because the the range of the mapping has to cover all $M$ element

Am I right? Thanks.

REPLY [2 votes]: I am not sure how can you get the answer of onto function because it is a complex question. However, I want to share what I know.
Given $|A| = m$ and $|B| = n$.
For one-to-one functions,

if $m < n$, there are $\frac{n!}{(n-m)!}$ one-to-one functions from A to B.
if $m = n$, there are $m!$ one-to-one functions from A to B.
if m > n, there are $0$ one-to-one functions from A to B.

For onto functions,

if $m < n$, there are $0$ functions from A onto B.
if $m = n$, there are  $m!$ onto functions.
if $m = n+1$, then there are $n \cdot {n+1\choose 2} \cdot (n-1)! = \frac{n(n+1)!}{2!}$functions A onto B.

You can get more detailed information from this pdf document.
enter link description here