How many ways are there to arrange two digits into an n digit number, when both digits must be used? I know the answer to this question is $2^n-2$, but I am unsure of how this answer is gotten. Could someone please explain to me how the answer is gotten step by step? Also, how many ways would there be to arrange 3,4, or 5 digits into an n digit number? Thanks!

If the number must contain both digits then the number of ways is
$$
\sum_{k=1}^{n-1} \left(
\begin{array}{c}
n\\
k
\end{array}\right) = 2^n - 2
$$
Suppose the two digits are $a$ and $b$, $a\neq b$. Then the number of ways to choose $k$ of the digits to be equal to $a$ is
$$
\left(
\begin{array}{c}
n\\
k
\end{array}\right)
$$
All remaining digits are $b$, so there is no choice to make for them. Now you simply sum up all the possibilities $(k = 1,\ldots,n-1)$, ignoring the cases $k = 0,n$, in which the number would only contain a single digit.
