Magic Square Generator

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.

magic
square
puzzle
Share this tool:
Quick Presets
Choose a magic square size to get started
Square Options
Select the size of your magic square

Odd-order sizes only — generated using the Siamese (De la Loubère) method

How it works: A magic square is a grid of distinct positive integers where every row, column, and main diagonal sums to the same value — the magic constant. For an n×n square the magic constant is n(n²+1)/2. This generator uses the classic Siamese method: place 1 in the middle of the top row, then move diagonally up-right for each successive number, wrapping around edges and dropping down when a cell is occupied.

Complete Guide: Magic Square Generator

Everything you need to know about using this tool effectively

What is Magic Square Generator?

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.

Key Features
Generates magic squares of any size (3x3 and up)
Shows the magic constant
Validates all row, column, and diagonal sums
Copy square to clipboard
Download as text or image
Runs in the browser with no uploads
Step-by-step construction option
Real-time generation
Common Use Cases
When and why you might need this tool

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.

How to Use This Tool
Step-by-step guide to get the best results
1

Select grid size

Choose the dimensions (e.g., 3x3, 4x4, 5x5).

2

Generate

Click Generate to create the magic square.

3

Verify the constant

The tool shows the magic constant and verifies all sums.

4

Copy or download

Copy the square or save it.

Pro Tips
1

The magic constant for an n x n square is n(n^2+1)/2.

2

3x3 magic squares always have a constant of 15.

3

4x4 magic squares have a constant of 34.

4

Odd-sized squares use the Siamese method. Even-sized squares use different algorithms.

Frequently Asked Questions
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.