Binomial random variable with coin flips. How do we get the formula $P(X=h) = \binom{n}{h}p^h(1-p)^{n-h}$?

The flips are independent, each with probability $p$ of being a head or $1-p$ of being a tail. Each of the $\binom{n}{h}$ choices of $h$ flips to be heads gives a head-tail sequence. Its probability is a product of $p$ and $1-p$ factors for heads and tails respectively, i.e. $p^h(1-p)^{n-h}$. (Or in @N.F.Taussig's words: "Since each of the $h$ heads has probability $p$ of occurring and each of the $n−h$ tails has probability $1−p$ of occurring, the probability that a particular sequence of $h$ heads and $n−h$ tails will occur is $p^h(1−p)^{n−h}$.") Together, these have probability $\binom{n}{h}p^h(1-p)^{n-h}$. As a sanity check,$$\sum_{h=0}^n\binom{n}{h}p^h(1-p)^{n-h}=(p+1-p)^n=1^n=1$$by the binomial theorem, so probabilities sum to $1$ as expected.


I can see that there are $\binom{n}{h}$ ways to choose a $h$-length subset of an $n$-length set (i.e. there are $\binom{n}{h}$ $n$-length sequences where we see $h$ heads),

Say, rather, $\tbinom n h$ is the count of ways to select $h$ elements from a set of $n$ distinct elements.   For example, the ways to select $h$ positions from a sequence of $n$ trials.

Thus $\tbinom nh$ is the count of ways to arrange $h$ heads among $n$ trial results.

but why do we multiply that with the probability? Furthermore, why do we multiply the probabilities of heads and tails together?

$p$ is the probability that a trial will result in heads.   $p^h$ is the probability that $h$ independent trials will do so.   $(1-p)^{n-h}$ is the probability that $n-h$ independent trials will result in tails.   $p^h(1-p)^{n-h}$ is therefore the probability that the first $h$ independent trials will result in heads and the next $n-h$ independent trials will result in tails.

However that is for a particular arrangement of $h$ heads and $n-h$ tails.   We want the probability for any arrangement of that many heads and tails among $n$ trials.   So we must multiply by the count of such arrangements (since all arrangements are equally probable).$$\mathsf P(H{=}h) ~=~\dbinom n h p^h(1-p)^{(n-h)}\qquad\big[h\in\Bbb N, 0\leq h\leq n\big]$$