Magic Square Generator

M = n(n²+1)/2

CalculatorsFreeNo Signup
4.7(192 reviews)
All Tools

Loading tool...

About Magic Square Generator

A magic square generator creating n×n grids using numbers 1 to n² where all rows, columns, and both diagonals have the same sum M = n(n²+1)/2. Uses Siamese, LUX, and doubly-even methods for different orders. Client-side.

Magic Square Generator Features

  • Generation
  • Magic constant
  • Odd/even methods
  • Verification
  • Lo Shu
Magic square: n×n grid with 1..n², all rows/columns/diagonals sum to M = n(n²+1)/2. The 3×3 Lo Shu (洛書) is humanity's oldest: M=15. Normal magic squares exist for all n≥3. Odd: Siamese method. Doubly-even (4k): symmetric swap. Singly-even (4k+2): LUX method.

How to Use

Enter order n:

  • Generate: Complete magic square
  • Verify: Check all sums
  • Constant: M = n(n²+1)/2

Construction Methods

Odd n: Siamese (de la Loubère) — start top-center, move NE, drop down on collision. Doubly-even (n=4k): fill naturally, swap complementary pairs. Singly-even (n=4k+2): LUX method by Conway.

History

Lo Shu (洛書): Chinese legend ~2200 BCE. Dürer's 4×4 (1514, Melancolia I) includes 15-14 in bottom row = year. Indian magic squares from ~10th century. Islamic mathematicians created large orders.

Step-by-Step Instructions

  1. 1Enter order n.
  2. 2Generate square.
  3. 3Verify sums.
  4. 4Check constant.
  5. 5Try different sizes.

Magic Square Generator — Frequently Asked Questions

Is the 3×3 magic square unique?+

Essentially yes! There's only one normal 3×3 magic square (Lo Shu), up to rotation and reflection. That gives 8 variants total. For 4×4: 880 essentially different squares. For 5×5: 275,305,224 — it explodes.

Why no 2×2 magic square?+

M would be 2(5)/2=5. But four numbers 1,2,3,4 in a 2×2 grid: each row sums to at most 3+4=7 and at least 1+2=3. Both rows summing to 5 requires {1,4} and {2,3}, but then columns sum to 1+2=3 or 4+3=7. Impossible!

What's a pandiagonal magic square?+

All broken diagonals ALSO sum to M (not just the main two). The smallest pandiagonal exists for 4×4. No pandiagonal 3×3 is possible. They're also called 'panmagic' or 'diabolic' squares.

Share this tool: