How many ways can 8 teachers be distributed among $4 $ schools?

With teachers and schools distinct and every school must have at least one teacher assigned to it, I would approach via inclusion-exclusion.

Let the schools be labeled $a,b,c,d$. Let the teachers be labeled $1,2,3,\dots,8$.

Let event $A$ be the event that school $a$ has no teachers assigned to it. Similarly $B,C,D$ are the events that school $b,c,d$ have no teachers assigned to them respectively.

Then $|A\cup B\cup C\cup D|$ is the set of ways to distribute the teachers which is "bad", yielding a school without a teacher in it.

$|A|$ (and similarly $|B|,|C|,|D|$) can be described as the functions from $\{1,2,3,\dots,8\}$ to $\{b,c,d\}$. From earlier example, we know that there are $3^8$ such functions.

$|A\cap B|$ (and similarly $|A\cap C|,|A\cap D|,\dots$) can be described as the functions from $\{1,2,\dots,8\}$ to $\{c,d\}$. From earlier example, we know that there are $2^8$ such functions.

Similarly, we calculate $|A\cap B\cap C|=1^8$ and $|A\cap B\cap C\cap D|=0^8$

Applying inclusion-exclusion then, we have $|A\cup B\cup C\cup D|=\binom{4}{1}3^8-\binom{4}{2}2^8+\binom{4}{3}1^8-\binom{4}{4}0^8=4\cdot 3^8-6\cdot 2^8+4=24712$

As those were the "bad" outcomes out of the $4^8$ total number of ways to distribute the teachers regardless, there are then $4^8-24712=40824$ good ways to distribute the teachers.


A shorter solution using more complicated formulae which take some time to learn appears in the chart I linked to in the comments above. We are able to describe this as trying to count the number of surjective functions from $\{1,2,\dots,8\}$ to $\{a,b,c,d\}$.

We can accomplish this by first counting how many ways there are to partition $\{1,2,\dots,8\}$ into $4$ nonempty subsets, and then choose how to label the subsets.

We can accomplish the first step in $\left\{\begin{array}{}8\\4\end{array}\right\}$ number of ways. (here $\left\{\begin{smallmatrix}n\\r\end{smallmatrix}\right\}$ represents the stirling number of the second kind $S(n,r)$). We can accomplish the second step in $4!$ number of ways, yielding a final total of $4!\cdot \left\{\begin{array}{}8\\4\end{array}\right\}=40824$ ways. (wolfram)


Assuming distinct teachers, distinct schools, and having identified the $5$ patterns, a foolproof mechanical way is to sum up the product of two multinomial coefficients for each case, one for the pattern, the other for the frequencies of singletons, doubles, triples, etc, viz.

$\binom{8}{1,1,1,5}\binom{4 }{3,1} + \binom{8}{1,1,2,4}\binom{4}{2,1,1} + \binom{8}{1,1,3,3}\binom{4}{2,2} + \binom{8}{1,2,2,3}\binom{4}{1,2,1} + \binom{8}{2,2,2,2}\binom44 = 40824$

And if preferring permutations to multinomial coefficients, the equivalent expression

$\frac{8!}{1!1!1!5!}\cdot\frac{4!}{3!1!} + \frac{8!}{1!1!2!4!}\cdot\frac{4!}{2!1!1!} + \frac{8!}{1!1!3!3!}\cdot\frac{4!}{2!2!}+\frac{8!}{1!2!2!3!}\cdot\frac{4!}{1!2!1!}+ \frac{8!}{2!2!2!2!}\cdot\frac{4!}{4!} = 40824 $