Mathwords logoMathwords

Magic Cube — Definition, Formula & Example

A magic cube is a three-dimensional version of a magic square. The numbers 1 through n3n^3 fill an n×n×nn \times n \times n block so that every straight line of nn cells running parallel to an edge, plus the four corner-to-corner diagonals, has the same sum.

A (simple) magic cube of order nn is a bijection from the cells of an n×n×nn \times n \times n array to {1,2,…,n3}\{1, 2, \dots, n^3\} such that the 3n23n^2 orthogonal lines (rows, columns, and pillars) and the 4 space diagonals each sum to the magic constant M=n(n3+1)2M = \frac{n(n^3+1)}{2}. If, in addition, the 2 diagonals of each of the 3n3n orthogonal cross-sections (the planar diagonals) also sum to MM, the cube is called perfect. Terminology varies between authors, so check which conditions a source requires. No magic cube of order 2 exists. Order 3 has simple magic cubes but no perfect ones. No perfect cube of order 4 exists either, and the smallest known perfect magic cube has order 5 (found by Walter Trump and Christian Boyer in 2003).

Key Formula

M=n(n3+1)2M = \frac{n(n^3 + 1)}{2}
Where:
  • MM = Magic constant: the required sum of every row, column, pillar, and space diagonal
  • nn = Order of the cube: the number of cells along each edge

Worked Example

Problem: A 3×3×3 magic cube uses the numbers 1 through 27. Find its magic constant without the formula. Then verify it on the cube shown in Step 3.
Step 1: Add all 27 entries using the sum of the first 27 positive integers.
1+2+⋯+27=27×282=3781 + 2 + \cdots + 27 = \frac{27 \times 28}{2} = 378
Step 2: The cube contains 3×3=93 \times 3 = 9 rows, 3 in each of 3 layers. These rows never overlap and together cover every cell, so the 9 row sums add up to the total.
9M=378⟹M=429M = 378 \quad\Longrightarrow\quad M = 42
Step 3: Here are the cube's three layers, from top to bottom. Check the pillar through the center, which reads straight down through the middle cells (7, 14, 21). Then check the space diagonal from the top-left-front corner to the bottom-right-back corner (8, 14, 20). All 27 orthogonal lines and all 4 space diagonals give 42, which makes 31 conditions in total. A 3×3 magic square has only 8.
824101272322119151262514322713191765211618420\begin{array}{ccc} 8 & 24 & 10 \\ 12 & 7 & 23 \\ 22 & 11 & 9 \end{array} \quad \begin{array}{ccc} 15 & 1 & 26 \\ 25 & 14 & 3 \\ 2 & 27 & 13 \end{array} \quad \begin{array}{ccc} 19 & 17 & 6 \\ 5 & 21 & 16 \\ 18 & 4 & 20 \end{array} 7+14+21=42,8+14+20=427 + 14 + 21 = 42, \qquad 8 + 14 + 20 = 42
Answer: The magic constant of a 3×3×3 magic cube is 42, which matches the formula M=3(27+1)2=42M = \frac{3(27+1)}{2} = 42.

Why It Matters

Magic cubes show how fast constraints pile up as dimension grows. Order 3 needs 31 equal sums instead of 8. This is why the smallest perfect magic cube, of order 5, was found only by computer search in 2003. Note one naming clash: the Rubik's Cube was first sold in Hungary as the Magic Cube, but it is a twisting puzzle with no number sums at all.

Common Mistakes

Mistake: Assuming every layer of a magic cube must itself be a magic square.
Correction: A simple magic cube only requires its rows, columns, pillars, and 4 space diagonals to sum to MM. The diagonals inside a layer are not required to match. In the example's top layer, 8+7+9=248 + 7 + 9 = 24, not 42. Only a perfect magic cube adds the condition on these planar diagonals.

Related Terms

  • Magic Square — The 2D version, with rows, columns, and two diagonals only
  • Cube Number — Gives n cubed, the number of entries filled
  • Diagonal Of A Cube — Space diagonals form the four extra magic lines here
  • Knight's Tour — Numbered tours can produce semi-magic square arrangements
  • Three-Dimensional — Magic cubes extend magic squares into three dimensions