I have a painted cube, which is cut into $n^3$ smaller cubes. I now want to find the number of cubes which have $1$,$2$,$3$ sides painted. I know the long way round of taking each cube and putting them into different categories... but is there a short way or formula to do it?
$1$ face painted - You have to consider all the faces. There are $6$ faces, each with $(n-2)^2$ cubes with $1$ face painted . That gives you the formula $$6*(n-2)^2$$
$2$ faces painted - You have to take the edges. There are $12$ edges, each edge having $n-2$ cubes with $2$ faces painted . That gives you the formula $$12*(n-2)$$
$3$ faces painted - You have to take the corners alone. That gives you the formula $$8$$
Extra - $0$ faces painted - You have to consider the interior alone which gives $$(n-2)^3$$
This is an addendum to Win Vineeth's excellent answer: the particular counts fall out of the algebraic expansion (using the Binomial Theorem) of $n^3$, where we write $n = (n-2) + 2$: $$ \bigl( (n-2) + 2 \bigr)^3 = (n-2)^3 + 6(n-2)^2 + 12(n-2) + 8 $$
This approach generalizes by letting $t$ be the "thickness" of the boundary (the part that gets painted). The original question uses $t=1$. The expansion now looks like: $$ \bigl( (n-2t) + 2t \bigr)^3 = (n-2t)^3 + 6(n-2t)^2t + 12(n-2t)t^2 + 8t^3 $$ Now, the power of $t$ serves as a placeholder for the number of sides that got painted. For example, if you want to know how many subcubes got painted on $2$ sides, then look at the coefficient of $t^2$, namely $12(n-2t)$, which is $12(n-2)$ once you set $t=1$. This is an example of a generating function, where a sequence is encoded as the list of coefficients of a polynomial (or often infinite series).
This approach also has the advantage of counting the number of boundary subhypercubes of a hypercube of any dimension: just expand $n^d$, where $d$ is the dimension.