Magic Square Generator
Generate magic squares of odd orders where every row, column, and diagonal sums to the same magic constant. Perfect for mathematical puzzles, number theory exploration, and educational demonstrations of the Siamese method algorithm.
Odd-order sizes only — generated using the Siamese (De la Loubère) method
Complete Guide: Magic Square Generator
Everything you need to know about using this tool effectively
The Magic Square Generator creates n x n grids where every row, column, and diagonal adds up to the same total (the magic constant). You choose the grid size (3x3, 4x4, 5x5, etc.) and the tool generates a valid magic square. The magic constant for an n x n square using numbers 1 to n^2 is n(n^2+1)/2. All processing happens in the browser.
This tool applies magic square construction algorithms to fill an n x n grid with distinct numbers from 1 to n^2 such that all rows, columns, and diagonals sum to the same value. It validates the result by checking all sums.
Solving math puzzles
Generate magic squares for puzzle games or mathematical challenges.
Teaching arithmetic
Show students how numbers can be arranged so all sums are equal.
Creating game boards
Generate magic square patterns for board games or grid-based puzzles.
Exploring number theory
Study the properties of magic squares and their construction methods.
Select grid size
Choose the dimensions (e.g., 3x3, 4x4, 5x5).
Generate
Click Generate to create the magic square.
Verify the constant
The tool shows the magic constant and verifies all sums.
Copy or download
Copy the square or save it.
The magic constant for an n x n square is n(n^2+1)/2.
3x3 magic squares always have a constant of 15.
4x4 magic squares have a constant of 34.
Odd-sized squares use the Siamese method. Even-sized squares use different algorithms.
What is a magic square?
A magic square is an n x n grid filled with distinct numbers from 1 to n^2 where all rows, columns, and diagonals sum to the same value (the magic constant).
What is the magic constant?
The magic constant is the sum that every row, column, and diagonal equals. For an n x n square, it is n(n^2+1)/2.
Is my data sent to a server?
No. All generation happens in your browser. Nothing is transmitted.
What sizes are supported?
Any size from 3x3 upward. Larger squares take longer to generate.
Are all magic squares the same?
No. For most sizes, there are many different valid magic squares. Each generation produces a different arrangement.