Free online tools to generate, calculate, convert, format, transform, and de/en-code.
 

Magic Square Generator

Generate magic squares where all rows, columns, and diagonals sum to the same magic constant. This tool uses the Siamese method (De la Loubère's algorithm) for odd-sized squares.

Enter an odd number between 3 and 15

What is a Magic Square?

A magic square is a square grid filled with distinct numbers (usually consecutive integers starting from 1) arranged so that the sum of numbers in each row, column, and diagonal is the same. This sum is called the magic constant.

Magic Constant Formula

For a magic square of order n (an n×n grid) using numbers from 1 to n²:

Magic Constant = n × (n² + 1) / 2

For example, a 3×3 magic square has a magic constant of 3 × (9 + 1) / 2 = 15.

The Siamese Method

This generator uses the Siamese method (also called De la Loubère's method), a simple algorithm for constructing magic squares of odd order:

  1. Start by placing 1 in the middle of the top row
  2. Move diagonally up and to the right to place the next number
  3. If this move goes outside the square, wrap around to the opposite side
  4. If the cell is already filled, move down one cell from the last number instead
  5. Repeat until all numbers are placed
History

Magic squares have fascinated mathematicians and mystics for thousands of years. They appear in:

  • Ancient China - The Lo Shu Square (3×3) dates back to 650 BCE
  • India - Used in astrological calculations and temple designs
  • Islamic Mathematics - Extensively studied during the medieval period
  • European Renaissance - Featured in Albrecht Dürer's engraving "Melencolia I" (1514)
Fun Fact: The sum of any two opposite corners in a magic square always equals the magic constant! Try it with any generated square.

Feedback

Help us improve this page by providing feedback:


Share with