The cubes with 2 faces painted will be the cubes on the sides except the corner ones.
Therefore, face on the top and bottom will have 8+8=16 cubes and the front and the back face will have 4+4=8 cubes.
The cubes on the other two faces have been covered by the above four.
Therefore, total number of cubes =8+16=24.