Magic Sum Calculator

Magic constant n(n²+1)/2, magic square generator for any order, and a square checker.

  1. Enter valuesUse your own inputs or an example
  2. CalculateApply your selected settings
  3. View resultExplore the answer and explanation

Choose what to calculate

Enter your values below to get started.

Examples:
What do you want?
3 to 30 for a generated square; any whole number for the constant.
1 for a normal magic square.
One row per line; numbers separated by spaces or commas.
Reset restores the default values.

Tips for this calculator

Set First number and Step to build a square from 5, 7, 9, … instead of 1, 2, 3, ….

In Check my square, a square that fails is drawn with the wrong lines in orange.

The Table tab of a generated square copies straight into a spreadsheet.

No 2 × 2 magic square with different numbers exists; every other order from 3 up has one.

A magic sum calculator finds the magic constant of an n × n magic square, the number that every row, column and main diagonal adds up to. For a square filled with 1 to n², the magic sum is M = n(n² + 1)/2: 15 for 3 × 3, 34 for 4 × 4 and 65 for 5 × 5. The calculator builds a magic square of any order from 3 to 30 and checks a square you type in.

What is a Magic Sum?

A magic sum (magic constant) is the total that every row, every column and both main diagonals of a magic square add up to. In the 3 × 3 Lo Shu square below, all 8 lines add up to 15.

4923578164+9+2=4+5+6=2+5+8=15\begin{array}{|c|c|c|}\hline 4 & 9 & 2 \\ \hline 3 & 5 & 7 \\ \hline 8 & 1 & 6 \\ \hline\end{array} \qquad 4 + 9 + 2 = 4 + 5 + 6 = 2 + 5 + 8 = 15

A normal magic square of order n uses each whole number from 1 to n² exactly once. Its magic sum depends only on n: 15 for n = 3, 34 for n = 4, 65 for n = 5, 111 for n = 6 and 260 for n = 8.

The Lo Shu is the oldest known magic square; Chinese legend tells of a turtle carrying its pattern out of the Luo River. Up to rotation and reflection, the Lo Shu is the only normal 3 × 3 magic square.

InteractiveTurn the Lo Shu square and check every line

How Does the Magic Sum Calculator Work?

The magic sum calculator works in 3 modes: it computes M = n(n² + 1)/2, builds a magic square with the method that fits n, or adds every line of your square and compares the sums. Every generated square is checked line by line before it is shown.

InteractivePlace the numbers with the Siamese method
  1. Odd n: Siamese method

    Start with 1 in the middle of the top row, move up and right, and drop down one cell when the target is taken.

  2. n divisible by 4

    Write 1 … n² in order and replace k by n² + 1 − k on the diagonals of each 4 × 4 block.

  3. n = 4m + 2

    John Horton Conway's LUX method expands an odd square of order n/2 into 2 × 2 blocks.

  4. Check

    All 2n + 2 lines are added; the checker labels a square magic, semi-magic or not magic.

Magic Sum Formula

The magic sum formula for a normal n × n magic square is M = n(n² + 1)/2. It comes from sharing the total of 1 + 2 + … + n² equally between the n rows.

Derivation

1+2+⋯+n2=n2(n2+1)2  ⇒  M=1n⋅n2(n2+1)2=n(n2+1)21 + 2 + \cdots + n^2 = \frac{n^2(n^2+1)}{2} \;\Rightarrow\; M = \frac{1}{n}\cdot\frac{n^2(n^2+1)}{2} = \frac{n(n^2+1)}{2}

The first step is the formula for the sum of the first N whole numbers, N(N + 1)/2, credited to Carl Friedrich Gauss, with N = n².

Squares Built from Any Arithmetic Sequence

For the numbers a, a + d, a + 2d, …, a + (n² − 1)d:

M=n a+d n(n2−1)2M = n\,a + d\,\frac{n(n^2-1)}{2}

With a = 1 and d = 1 this reduces to n(n² + 1)/2.

Total of All Cells

S=n⋅M=n2(n2+1)2S = n \cdot M = \frac{n^2(n^2+1)}{2}
InteractiveMagic constant for n = 3 to 15

Types of Magic Squares

Magic squares are grouped into 3 types by order (odd, doubly even, singly even) and into 4 types by their lines (semi-magic, magic, panmagic, associative). Each order type needs its own construction method.

InteractiveBuild orders 3 to 12 and see the method

Odd order (3, 5, 7, …)

Built with the Siamese method. M = 15, 65, 175, …

Doubly even (4, 8, 12, …)

n divisible by 4. Built by the diagonal-swap pattern. M = 34, 260, 870, …

Singly even (6, 10, 14, …)

n = 4m + 2, the hardest case. Built by the LUX method. M = 111, 505, 1,379, …

Semi-magic

Rows and columns add up to M, but at least 1 diagonal does not.

Panmagic

The broken diagonals add up to M too. The smallest panmagic squares are 4 × 4.

Associative

Every pair of cells symmetric about the center adds up to n² + 1. The Lo Shu and Dürer's square are associative.

How to Make a Magic Square by Hand

To make an odd magic square by hand, put 1 in the middle of the top row, then place each next number one cell up and one cell right, wrapping around the edges, and move one cell down whenever the cell is full. Here is the 3 × 3 square.

  1. 1 goes in the top-middle cell.
  2. Up-right from 1 leaves the grid, so wrap to the bottom row, right column: 2.
  3. Up-right from 2 wraps to the left column, middle row: 3.
  4. Up-right from 3 is taken by 1, so drop below 3: 4. Continue: 5 (center), 6 (top right), 7 below 6, 8, 9.
  5. Result: 8 1 6 / 3 5 7 / 4 9 2, every line = 15.
InteractiveStep through 3 hand methods

    Famous Magic Squares and Their Magic Sums

    The 4 best-known magic squares are the Lo Shu (sum 15), Albrecht Dürer's 1514 square (sum 34), the Sagrada Família square (sum 33) and Srinivasa Ramanujan's birthday square (sum 139). Each one shows a different trick.

    • Lo Shu (China): the only normal 3 × 3 magic square, up to rotation and reflection.
    • Dürer's Melencolia I (1514): a normal 4 × 4 square whose bottom row spells the year, 15 14.
    • Sagrada Família, Barcelona: sculptor Josep Maria Subirachs repeated 10 and 14 to reach 33 instead of 34.
    • Ramanujan's square: its top row is the date 22-12-1887; every line adds up to 139.
    • Counting squares: Bernard Frénicle de Bessy listed all 880 normal 4 × 4 squares in 1693; there are 275,305,224 of order 5, counted by Richard Schroeppel in 1973.
    Interactive4 famous squares, every line checked

    Common Mistakes with Magic Sums

    • Using n² instead of n: M = n(n² + 1)/2 multiplies by n, not n²; for n = 4 it is 4 × 17 / 2 = 34.
    • Checking only rows: a square with equal rows and columns but unequal diagonals is only semi-magic.
    • Applying the Siamese method to even n: it works only for odd orders.
    • Expecting a 2 × 2 square: none exists with 4 different numbers.
    • Wrong target for shifted numbers: a square of 5, 7, …, 21 has M = 39, not 15.
    InteractiveTrue or false: magic sums
    1. The magic sum of a normal 4 × 4 magic square is 34.

    2. A normal 2 × 2 magic square exists.

    3. The center of every normal 3 × 3 magic square is 5.

    4. The Sagrada Família square uses each of 1 to 16 once.

    5. The Siamese method builds magic squares of any odd order.

    Score: 0 / 5

    How to Use the Magic Sum Calculator

    Pick Magic constant, Generate a square or Check my square, fill in the order n (or paste your square) and press Calculate. The result shows the magic sum, the square itself, the step-by-step working and a table you can copy.

    InteractiveLoad a ready-made magic square task

    Each button fills the calculator and runs it.

    1. Pick the mode

      Each mode shows only the inputs it needs.

    2. Set n

      Any whole number for the constant; 3 to 30 for a generated square.

    3. Change the numbers (optional)

      First number and step build squares from sequences such as 10, 20, 30, ….

    4. Check a square

      Paste one row per line; wrong lines turn orange in the Square chart.

    Real-Life Uses of Magic Sums

    Magic sums are used in recreational mathematics, puzzle design, art and the teaching of arithmetic. 5 examples:

    • Games: Pick 15 (number scrabble) is tic-tac-toe on the Lo Shu square: 3 numbers adding up to 15 form a line.
    • Puzzles: magic square fill-ins, KenKen and Kakuro train the same addition skills.
    • Art and architecture: Dürer's engraving and the Sagrada Família façade use magic squares as symbols.
    • Classroom practice: checking 2n + 2 line sums is a standard addition drill.
    • Experimental design: magic squares are close relatives of Latin squares, which agricultural statistician Ronald Fisher used to lay out field trials.
    InteractivePlay Pick 15 against the computer

    Magic Sum Examples

    7 magic square tasks and their answers. Press Try to load any row into the calculator.

    Magic Sum Examples
    TaskDetailAnswerCalculator
    Magic constantn = 3M = 15
    Magic constantn = 4M = 34
    Magic constantn = 10M = 505
    Generate5 × 5, SiameseM = 65
    Generate6 × 6, LUXM = 111
    CheckDürer's 1514 squareNormal magic square, M = 34
    CheckSagrada Família squareMagic square with repeats, M = 33

    Popular Magic Sum Problems

    Solve each one, then reveal the answer or check it in the calculator.

    1. What is the magic sum of a normal 5 × 5 magic square?

      M = \frac{5(25+1)}{2}
      Show answer65
    2. What is the magic sum of a normal 8 × 8 magic square?

      M = \frac{8(64+1)}{2}
      Show answer260
    3. A 3 × 3 magic square uses 5, 7, 9, …, 21. What is its magic sum?

      M = 3\cdot 5 + 2\cdot\frac{3(9-1)}{2}
      Show answer39
    4. Is 2 7 6 / 9 5 1 / 4 3 8 a magic square?

      Show answerYes, a normal magic square with M = 15
    5. What is the magic sum of Ramanujan's square 22 12 18 87 / 88 17 9 25 / 10 24 89 16 / 19 86 23 11?

      Show answer139
    6. Classify the square 1 2 3 / 2 3 1 / 3 1 2.

      Show answerSemi-magic: rows, columns and the main diagonal are 6, the anti-diagonal is 9

    Explore More Sum Calculators

    Discover 67 free sum calculators across different categories. Find the right calculator for your needs.

    Browse All 67 Calculators
    Questions and answers

    Frequently Asked Questions

    What is a magic sum calculator?

    A magic sum calculator is an online tool that returns the magic constant M = n(n² + 1)/2 of an n × n magic square, builds a magic square of a chosen order and checks whether a square you enter is magic.

    What is the magic sum of a 3 × 3 square?

    The magic sum of a normal 3 × 3 magic square is 15: 3(9 + 1)/2 = 15. The numbers 1 to 9 add up to 45, shared equally between 3 rows.

    What is the magic constant of a 4 × 4 magic square?

    The magic constant of a normal 4 × 4 magic square is 34, since 4(16 + 1)/2 = 34. Dürer's 1514 square is a famous example.

    Is there a 2 × 2 magic square?

    No, a 2 × 2 square with different numbers cannot have equal rows, columns and diagonals. Every order n ≥ 3 has magic squares.

    How do you make a magic square with an odd number of rows?

    Use the Siamese method: put 1 in the middle of the top row, place each next number one cell up and one cell right (wrapping around the edges), and move one cell down when the cell is taken.

    How many 4 × 4 magic squares are there?

    There are 880 normal 4 × 4 magic squares, not counting rotations and reflections, as Bernard Frénicle de Bessy found in 1693.

    What is the difference between a magic and a semi-magic square?

    In a magic square, rows, columns and both main diagonals share one sum. In a semi-magic square, only the rows and columns do.

    Can a magic square start from a number other than 1?

    Yes, any arithmetic sequence a, a + d, … works with the same layout. Its magic sum is M = n·a + d·n(n² − 1)/2, so 5, 7, …, 21 in a 3 × 3 square gives 39.

    What is a panmagic square?

    A panmagic square is a magic square whose broken diagonals (diagonals that wrap around the edges) add up to the magic sum as well. The smallest panmagic squares have order 4.

    Conclusion

    The magic sum of a normal n × n magic square is M = n(n² + 1)/2, and the magic sum calculator returns it for any n, builds a square for orders 3 to 30 and checks squares you type in. Use the Siamese method for odd n, the diagonal swap for multiples of 4 and the LUX method for 6, 10, 14 and the other singly even orders.

    Not sure which method builds your square? Answer up to 2 questions below.

    InteractiveWhich construction method fits your n?