A magic cube is a three-dimensional array of whole numbers, in which each row, column, and body diagonal (corner to corner, through the center) adds up to the same total. A perfect magic cube is one in which the diagonals of each vertical or horizontal slice through the cube also sum to the same value.
Suppose each row, column, and diagonal contains N numbers. The magic cube would then consist of N3 numbers, usually the integers from 1 to N3. In this case, the sum (or magic constant) is 1/2(N4 + N).