Magic Square Calculator - 3x3, 4x4, and Magic Constant
Use this magic square calculator to fill a 3x3 Lo Shu grid or a 4x4 Dürer grid. Set the order, start value, and step, then read the magic constant, the solved grid, and every row, column, and diagonal sum.
Magic Square Calculator
Solved Magic Square Grid
The grid updates as you change the order, start, or step. Every row, column, and main diagonal of the displayed grid sums to the Magic Constant shown on the right.
Results
What Is a Magic Square Calculator?
A magic square calculator fills a grid of numbers so every row, column, and main diagonal sums to the same total, called the magic constant. Pick an order, start, and step, and the calculator returns the solved grid, the magic constant, and every line sum in one read.
- • Puzzle solving: Solve a missing cell in a partially filled 3x3 or 4x4 square by reading the solved grid and magic constant.
- • Math class demos: Show the Lo Shu 3x3 and Dürer 4x4 grids next to the magic constant formula.
- • Recreational math: Try unusual start and step values and watch the line-sum property hold.
- • Verification of own work: Confirm a hand-built square against the eight or ten line sums.
A magic square is one of the oldest objects in recreational mathematics. The 3x3 Lo Shu square has been known in China for at least two thousand years, and Albrecht Dürer included a 4x4 magic square in his engraving Melencolia I in 1514. A normal magic square of order n contains each integer from 1 to n^2 once, and every line sums to the magic constant.
A magic square of order n has a built-in cross-check: the arithmetic mean of its n^2 cells equals the magic constant divided by n (5 for a normal 3x3 Lo Shu, 8.5 for a normal 4x4 Dürer). To confirm that mean on a hand-built grid, Average Calculator returns the arithmetic mean, sum, and count of any list of cell values in one pass.
How the Magic Square Calculator Works
The calculator combines the closed-form magic constant M = n(n^2 + 1) / 2 with the Lo Shu pattern (n = 3) and the Dürer pattern (n = 4), and applies a linear transform so the same shape works for any start and step. Every line sum is recomputed from the final grid so the displayed sums always match the displayed cells.
- n: The order of the square (3 for a 3x3 grid, 4 for a 4x4 grid).
- M: The magic constant, the value every row, column, and main diagonal sums to.
- start: The number placed in the cell that corresponds to a 1 in the base pattern. Default 1.
- step: The difference between consecutive integers in the square. Default 1.
The calculator re-sums each row, each column, and both main diagonals from the final cells, so the displayed sums always match the displayed grid. With step > 1 the cells become a stretched version of the Lo Shu or Dürer pattern, and the magic constant scales with step and shifts with start.
Order-3 Lo Shu square (start 1, step 1)
order = 3, start = 1, step = 1; M = 3 * 10 / 2 = 15
Grid: 8 1 6 / 3 5 7 / 4 9 2. All eight line sums equal 15.
The classical Lo Shu square, with the numbers 1 through 9 each appearing once.
Order-4 Dürer square (start 1, step 1)
order = 4, start = 1, step = 1; M = 4 * 17 / 2 = 34
Grid: 16 3 2 13 / 5 10 11 8 / 9 6 7 12 / 4 15 14 1. All ten line sums equal 34.
This is the square in Dürer's 1514 engraving Melencolia I. The middle cells 15 and 14 of the bottom row encode the year 1514.
According to Wolfram MathWorld, a normal magic square of order n contains each integer from 1 to n^2 once, and every row, column, and main diagonal sums to the magic constant n(n^2+1)/2.
When the grid uses many cells with multi-digit values, Long Addition Calculator lays out each row sum in stacked long form so the addition can be checked column by column.
Key Concepts Behind a Magic Square
Four small ideas explain why the Lo Shu and Dürer squares work and how the line-sum property extends to other start and step values.
Magic constant M
For a normal magic square of order n, the magic constant is M = n(n^2 + 1) / 2. The square uses 1 + 2 + ... + n^2, and dividing by n gives the per-line sum. Supported orders give M = 15 for n = 3 and M = 34 for n = 4.
Normal vs. general magic square
A normal magic square contains every integer from 1 to n^2 once. A general magic square only requires that every line sum to the same constant, and the start and step inputs cover the normal case and any equally spaced variant.
Line-sum property
Every row, column, and main diagonal adds up to M. The calculator reports all n rows, n columns, and 2 diagonals so the property can be checked against the magic constant on the same screen.
Lo Shu and Dürer constructions
The 3x3 Lo Shu square is unique up to rotation and reflection. The 4x4 Dürer square is one of 7040 normal order-4 squares, all related by rotation, reflection, and row/column swaps.
These four ideas are enough to build and verify a magic square by hand for n = 3 and n = 4. For larger orders, the Siamese, Strachey, and LUX methods start from the same magic constant and use the same line-sum property.
If you want to treat a magic square as a 2D array and explore its linear-algebra properties, Adjoint Matrix Calculator returns the adjugate of the corresponding matrix in one step.
How to Use the Magic Square Calculator
Pick the order, set the start and step, and read the solved grid, the magic constant, and every line sum on the right. The result panel updates as you change any input.
- 1 Choose the order: 3x3 (Lo Shu, M = 15) or 4x4 (Dürer, M = 34).
- 2 Set the start value: The smallest number in the grid. Use 1 for a normal square, 0 for 0 to n^2 - 1.
- 3 Set the step between cells: The difference between consecutive integers. Use 1 for normal, 2 for even numbers only.
- 4 Read the magic constant: The highlighted Magic Constant row shows the value that every row, column, and main diagonal must add up to.
- 5 Compare each line sum: All row, column, and diagonal rows show the recomputed line sum from the displayed grid, and they should all equal the magic constant.
- 6 Reset for a new puzzle: Press Reset to restore the default 3x3, start 1, step 1 inputs.
Example: a student is given the partial 3x3 grid [8, 1, 6 / 3, ?, 7 / 4, 9, 2] and asked for the missing cell. They set Order 3, Start 1, Step 1. The result panel shows magic constant 15 and the full Lo Shu grid, with the missing cell as 5.
When the puzzle asks for the total of 1 to n^2 in a normal magic square, Arithmetic Sequence Calculator returns the closed-form triangular sum n^2(n^2+1)/2 in one step, which is the same total used to derive the magic constant n(n^2+1)/2.
Benefits of Using This Magic Square Calculator
Pattern recognition is enough to build a 3x3 or 4x4 magic square, but writing one by hand invites arithmetic mistakes, and the magic constant is easy to forget. The calculator removes both risks.
- • Two orders in one tool: Switch between the 3x3 Lo Shu and 4x4 Dürer pattern with a single dropdown.
- • Magic constant built in: M = n(n^2 + 1) / 2 is applied to the start and step, so the highlighted Magic Constant row is always the correct target.
- • All line sums at once: Eight sums for 3x3 and ten for 4x4 appear next to the magic constant.
- • Reusable for offset squares: Build squares that use 0 to 8, even numbers only, or any equally spaced sequence, and the line sums stay equal.
- • Verifies hand-built squares: Read the recomputed line sums against the displayed magic constant to confirm a square you built on paper.
The biggest benefit is the immediate cross-check: if any line sum disagrees with the magic constant, the grid or formula is wrong, and the cause is usually a misplaced cell. With the Lo Shu and Dürer patterns built in, swapping two cells in row 2 is caught at a glance.
To check a hand-built square at a glance, copy the eight or ten line sums into a list and Mean Median Mode Range Calculator reports the range, median, and mean; for a true magic square the range is 0 and the mean equals the magic constant.
Factors That Affect the Result and Its Limits
A magic square is a discrete object, so there is no continuous parameter to estimate. The factors that change the result are the integer inputs you choose, and the limits are the supported orders.
Order n
The order sets the grid size and the magic constant. n = 3 gives M = 15; n = 4 gives M = 34. Other orders return a clear error.
Start value
The start value shifts every cell by the same amount. Changing start from 1 to 10 raises the magic constant by 30 for n = 3, and every line sum increases by 30.
Step between cells
The step multiplies the differences between cells. With step = 2 the square uses 1, 3, 5, ... and the magic constant doubles.
Order coverage
Only n = 3 and n = 4 are built in. n = 2 has no solution, n = 1 is trivial, and n >= 5 needs a different construction.
- • The calculator returns a clear error for any order other than 3 or 4. The 2x2 case has no solution, and orders 5 and above need a separate method.
- • For each supported order the calculator returns one canonical pattern. The full family of order-4 normal magic squares (7040 total) is not enumerated, but any one of them has the same magic constant and the same line-sum property.
- • The cells must form an arithmetic sequence defined by start and step. General magic squares with non-equally-spaced values are outside the scope of this tool.
The integer constraints above are the only real limits. Within them, the same line-sum property holds for every combination of start and step.
According to Wikipedia (Magic square), the order-n normal magic square uses the integers 1 through n^2 and has the magic constant n(n^2+1)/2; for n=3 the classical pattern is the Lo Shu square, and for n=4 Albrecht Dürer published a well-known example in 1514.
When you want to confirm a hand-built square by computing the difference between the largest and smallest line sums, Long Subtraction Calculator sets up the subtraction in stacked long form.
Frequently Asked Questions
Q: What is a magic square in math?
A: A magic square is an n by n grid of integers arranged so that every row, every column, and both main diagonals add up to the same number, called the magic constant. A normal magic square uses each integer from 1 to n^2 once, and the magic constant is M = n(n^2 + 1) / 2.
Q: What is the magic constant formula?
A: The magic constant is M = n(n^2 + 1) / 2 for a normal magic square of order n. For n = 3 this gives M = 15, and for n = 4 it gives M = 34. With start value s and step k, the magic constant becomes M = n * (s - k) + k * n * (n^2 + 1) / 2, which reduces to n(n^2 + 1) / 2 when s = k = 1.
Q: How do you solve a 3x3 magic square?
A: The 3x3 magic square is unique up to rotation and reflection. The classical Lo Shu pattern is 8 1 6 / 3 5 7 / 4 9 2, with every row, column, and diagonal summing to 15. The center cell is always 5, and the opposite cells (1 and 9, 2 and 8, 3 and 7, 4 and 6) sum to 10.
Q: What is the Lo Shu square?
A: The Lo Shu square is the unique normal 3x3 magic square, known in China for at least two thousand years. Its grid is 8 1 6 / 3 5 7 / 4 9 2, every line sums to 15, and the numbers 1 through 9 each appear once. The center cell is 5, and each pair of opposite cells sums to 10.
Q: Do 4x4 magic squares exist?
A: Yes. The most famous 4x4 normal magic square is in Albrecht Dürer's 1514 engraving Melencolia I, with grid 16 3 2 13 / 5 10 11 8 / 9 6 7 12 / 4 15 14 1 and magic constant 34. There are 7040 normal order-4 magic squares in total, related by rotation, reflection, and row/column swaps.
Q: Why are magic squares useful?
A: Magic squares are useful as recreational puzzles and as compact examples of combinatorial design. They appear in introductory number theory, in error-correcting codes, and in design of experiments where balanced row and column sums matter. In the classroom they are a quick way to practise addition, pattern recognition, and the idea of a single invariant (the magic constant) tying many lines together.