← All tools

Magic Square Generator

A magic square of order n is an n×n grid of the numbers 1 to n² in which every row, every column, and both main diagonals sum to the same magic constant M = n(n²+1)/2. Generate one for any supported order: odd orders (3, 5, 7, …) use the Siamese (de la Loubère) method, and doubly-even orders divisible by 4 (4, 8, 12, …) use the complement method. Each generated square is verified on the spot — all 2n+2 lines must equal M and every number 1…n² must appear exactly once. The 3×3 case is the ancient Lo Shu; the 4×4 inspired Dürer's Melencolia I. Everything runs locally in your browser.

Order n

Result

Magic squares. For order n the magic constant is M = n(n²+1)/2 (so M = 15 for n=3, 34 for n=4, 65 for n=5, 111 for n=6, 260 for n=8). The Siamese method (de la Loubère, for odd n) starts at the middle of the top row with 1, then repeatedly moves up-and-right wrapping at the edges; when the target cell is occupied it drops down one row instead. The complement method (for doubly-even n = 4k) fills 1…n² in row-major order, then replaces every cell not on a diagonal of its 4×4 block with its complement (n²+1 − value); the cells on those diagonals are kept, producing the characteristic pattern. Singly-even orders (n = 4k+2, like 6 and 10) are not supported here — they require Strachey's quadrant-swap construction (or Conway's LUX method), which is markedly more intricate than the two methods above. Pairs with the Latin Square / Number Properties tools. Everything runs locally — nothing leaves your browser.