Magic Squares of odd order
Magic Squares of odd order by Marios Mamzeris
This page presents the Mamzeris Method: a systematic approach to constructing associative magic squares of any odd order using simple two-pass transformations or direct mathematical formulas.
The Origin Story
I developed this method in 1988 while studying computer science. When my university's mathematics faculty presented what they called an 'unsolved problem' in magic square construction, they challenged me to apply my programming background to find a systematic solution. What emerged was a universal algorithmic method that works for any odd-order magic square. I used this method personally for over three decades before publishing it in 2020, along with a new universal closed-form formula that enables direct calculation of any cell position.
A Magic Square is an n × n square grid (where n is the number of cells on each side) filled with distinct positive integers in the range 1,2,...,n2 such that each cell contains a different integer and the sum of integers in each row, column, and diagonal is equal.
An associative magic square has an elegant property: pairs of numbers positioned symmetrically opposite the centre always sum to n2 + 1. For example, in a 7×7 square (n²=49), opposite pairs sum to 50. These are also called symmetric magic squares, and all associative magic squares are self-complementary. (Wikipedia)
The Mamzeris Method offers two complementary approaches:
1. Algorithmic Construction (detailed below): A two-pass table transformation using row and column shifts. Best for learning, teaching, or manual construction.
2. Universal Closed-Form Formula: A direct mathematical formula that computes the value of any cell position (x, y) for any odd order N. This formula was first published in 2025 and enables instant calculation without iterative steps. Best for programming, large squares, or individual cell calculations. View the complete mathematical formula
Algorithmic Construction Method:
To create any odd-order associative magic square quickly and efficiently using the algorithmic approach, we need to perform only two simple passes, which I call table transformations (shifts). The three tables below demonstrate the construction of a 31×31 magic square.
Pass 1: Begin with a table filled sequentially with all numbers from 1 to n2 (1st table below, with cells shifting shown in green). Perform a left shift of all rows, skipping the middle one: shift the first row by one cell, the second row by two cells, and so on, until the last (nth) row is shifted by n−1 cells.
Pass 2: Apply a similar transformation to columns instead of rows. Shift cells upward, starting with one cell in the leftmost column, two cells in the next column, and so on, until the last (nth) column is shifted by n−1 cells, skipping the middle column. This is shown in the 2nd table below with cells shifting in blue.
That's it. A magic square is ready. The completed square is shown in the 3rd table below, with alternating grey cells and highlighted yellow diagonals.
1. Initial Table: Begin with numbers from 1 to n2 arranged sequentially
The green arrow indicates the direction of the upcoming cell shift. Green-highlighted cells show which cells will move.

| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | ||
| 1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | |
| 2 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | |
| 3 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | |
| 4 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | |
| 5 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | |
| 6 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | |
| 7 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | |
| 8 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | |
| 9 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | |
| 10 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | |
| 11 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | |
| 12 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | |
| 13 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | |
| 14 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | |
| 15 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | |
| 16 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | |
| 17 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | |
| 18 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | |
| 19 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | |
| 20 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | |
| 21 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | |
| 22 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | |
| 23 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | |
| 24 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | |
| 25 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | |
| 26 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | |
| 27 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | |
| 28 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 | |
| 29 | 869 | 870 | 871 | 872 | 873 | 874 | 875 | 876 | 877 | 878 | 879 | 880 | 881 | 882 | 883 | 884 | 885 | 886 | 887 | 888 | 889 | 890 | 891 | 892 | 893 | 894 | 895 | 896 | 897 | 898 | 899 | |
| 30 | 900 | 901 | 902 | 903 | 904 | 905 | 906 | 907 | 908 | 909 | 910 | 911 | 912 | 913 | 914 | 915 | 916 | 917 | 918 | 919 | 920 | 921 | 922 | 923 | 924 | 925 | 926 | 927 | 928 | 929 | 930 | |
| 31 | 931 | 932 | 933 | 934 | 935 | 936 | 937 | 938 | 939 | 940 | 941 | 942 | 943 | 944 | 945 | 946 | 947 | 948 | 949 | 950 | 951 | 952 | 953 | 954 | 955 | 956 | 957 | 958 | 959 | 960 | 961 |
2. After First Pass: Rows shifted, columns ready for transformation
The blue arrow indicates the direction of the second shift. Blue-highlighted cells show which cells will move.

| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | ||
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 1 | |
| 2 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 32 | 33 | |
| 3 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 63 | 64 | 65 | |
| 4 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 94 | 95 | 96 | 97 | |
| 5 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 125 | 126 | 127 | 128 | 129 | |
| 6 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 156 | 157 | 158 | 159 | 160 | 161 | |
| 7 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | |
| 8 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | |
| 9 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | |
| 10 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | |
| 11 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | |
| 12 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | |
| 13 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | |
| 14 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | |
| 15 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | |
| 16 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | |
| 17 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | |
| 18 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | |
| 19 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | |
| 20 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | |
| 21 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | |
| 22 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | |
| 23 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | |
| 24 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | |
| 25 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | |
| 26 | 801 | 802 | 803 | 804 | 805 | 806 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | |
| 27 | 833 | 834 | 835 | 836 | 837 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | |
| 28 | 865 | 866 | 867 | 868 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | |
| 29 | 897 | 898 | 899 | 869 | 870 | 871 | 872 | 873 | 874 | 875 | 876 | 877 | 878 | 879 | 880 | 881 | 882 | 883 | 884 | 885 | 886 | 887 | 888 | 889 | 890 | 891 | 892 | 893 | 894 | 895 | 896 | |
| 30 | 929 | 930 | 900 | 901 | 902 | 903 | 904 | 905 | 906 | 907 | 908 | 909 | 910 | 911 | 912 | 913 | 914 | 915 | 916 | 917 | 918 | 919 | 920 | 921 | 922 | 923 | 924 | 925 | 926 | 927 | 928 | |
| 31 | 961 | 931 | 932 | 933 | 934 | 935 | 936 | 937 | 938 | 939 | 940 | 941 | 942 | 943 | 944 | 945 | 946 | 947 | 948 | 949 | 950 | 951 | 952 | 953 | 954 | 955 | 956 | 957 | 958 | 959 | 960 |
3. Completed Magic Square: Final result after both transformations
All rows, columns, and diagonals now sum to the magic constant. Grey cells alternate for visibility, and yellow highlights show the main diagonals.
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | ||
| 1 | 34 | 67 | 100 | 133 | 166 | 199 | 232 | 265 | 298 | 331 | 364 | 397 | 430 | 463 | 480 | 17 | 498 | 531 | 564 | 597 | 630 | 663 | 696 | 729 | 762 | 795 | 828 | 861 | 894 | 927 | 960 | |
| 2 | 66 | 99 | 132 | 165 | 198 | 231 | 264 | 297 | 330 | 363 | 396 | 429 | 462 | 479 | 527 | 49 | 530 | 563 | 596 | 629 | 662 | 695 | 728 | 761 | 794 | 827 | 860 | 893 | 926 | 959 | 1 | |
| 3 | 98 | 131 | 164 | 197 | 230 | 263 | 296 | 329 | 362 | 395 | 428 | 461 | 478 | 526 | 528 | 81 | 562 | 595 | 628 | 661 | 694 | 727 | 760 | 793 | 826 | 859 | 892 | 925 | 958 | 31 | 33 | |
| 4 | 130 | 163 | 196 | 229 | 262 | 295 | 328 | 361 | 394 | 427 | 460 | 477 | 525 | 558 | 560 | 113 | 594 | 627 | 660 | 693 | 726 | 759 | 792 | 825 | 858 | 891 | 924 | 957 | 30 | 32 | 65 | |
| 5 | 162 | 195 | 228 | 261 | 294 | 327 | 360 | 393 | 426 | 459 | 476 | 524 | 557 | 559 | 592 | 145 | 626 | 659 | 692 | 725 | 758 | 791 | 824 | 857 | 890 | 923 | 956 | 29 | 62 | 64 | 97 | |
| 6 | 194 | 227 | 260 | 293 | 326 | 359 | 392 | 425 | 458 | 475 | 523 | 556 | 589 | 591 | 624 | 177 | 658 | 691 | 724 | 757 | 790 | 823 | 856 | 889 | 922 | 955 | 28 | 61 | 63 | 96 | 129 | |
| 7 | 226 | 259 | 292 | 325 | 358 | 391 | 424 | 457 | 474 | 522 | 555 | 588 | 590 | 623 | 656 | 209 | 690 | 723 | 756 | 789 | 822 | 855 | 888 | 921 | 954 | 27 | 60 | 93 | 95 | 128 | 161 | |
| 8 | 258 | 291 | 324 | 357 | 390 | 423 | 456 | 473 | 521 | 554 | 587 | 620 | 622 | 655 | 688 | 241 | 722 | 755 | 788 | 821 | 854 | 887 | 920 | 953 | 26 | 59 | 92 | 94 | 127 | 160 | 193 | |
| 9 | 290 | 323 | 356 | 389 | 422 | 455 | 472 | 520 | 553 | 586 | 619 | 621 | 654 | 687 | 720 | 273 | 754 | 787 | 820 | 853 | 886 | 919 | 952 | 25 | 58 | 91 | 124 | 126 | 159 | 192 | 225 | |
| 10 | 322 | 355 | 388 | 421 | 454 | 471 | 519 | 552 | 585 | 618 | 651 | 653 | 686 | 719 | 752 | 305 | 786 | 819 | 852 | 885 | 918 | 951 | 24 | 57 | 90 | 123 | 125 | 158 | 191 | 224 | 257 | |
| 11 | 354 | 387 | 420 | 453 | 470 | 518 | 551 | 584 | 617 | 650 | 652 | 685 | 718 | 751 | 784 | 337 | 818 | 851 | 884 | 917 | 950 | 23 | 56 | 89 | 122 | 155 | 157 | 190 | 223 | 256 | 289 | |
| 12 | 386 | 419 | 452 | 469 | 517 | 550 | 583 | 616 | 649 | 682 | 684 | 717 | 750 | 783 | 816 | 369 | 850 | 883 | 916 | 949 | 22 | 55 | 88 | 121 | 154 | 156 | 189 | 222 | 255 | 288 | 321 | |
| 13 | 418 | 451 | 468 | 516 | 549 | 582 | 615 | 648 | 681 | 683 | 716 | 749 | 782 | 815 | 848 | 401 | 882 | 915 | 948 | 21 | 54 | 87 | 120 | 153 | 186 | 188 | 221 | 254 | 287 | 320 | 353 | |
| 14 | 450 | 467 | 515 | 548 | 581 | 614 | 647 | 680 | 713 | 715 | 748 | 781 | 814 | 847 | 880 | 433 | 914 | 947 | 20 | 53 | 86 | 119 | 152 | 185 | 187 | 220 | 253 | 286 | 319 | 352 | 385 | |
| 15 | 466 | 514 | 547 | 580 | 613 | 646 | 679 | 712 | 714 | 747 | 780 | 813 | 846 | 879 | 912 | 465 | 946 | 19 | 52 | 85 | 118 | 151 | 184 | 217 | 219 | 252 | 285 | 318 | 351 | 384 | 417 | |
| 16 | 513 | 546 | 579 | 612 | 645 | 678 | 711 | 744 | 746 | 779 | 812 | 845 | 878 | 911 | 944 | 481 | 18 | 51 | 84 | 117 | 150 | 183 | 216 | 218 | 251 | 284 | 317 | 350 | 383 | 416 | 449 | |
| 17 | 545 | 578 | 611 | 644 | 677 | 710 | 743 | 745 | 778 | 811 | 844 | 877 | 910 | 943 | 16 | 497 | 50 | 83 | 116 | 149 | 182 | 215 | 248 | 250 | 283 | 316 | 349 | 382 | 415 | 448 | 496 | |
| 18 | 577 | 610 | 643 | 676 | 709 | 742 | 775 | 777 | 810 | 843 | 876 | 909 | 942 | 15 | 48 | 529 | 82 | 115 | 148 | 181 | 214 | 247 | 249 | 282 | 315 | 348 | 381 | 414 | 447 | 495 | 512 | |
| 19 | 609 | 642 | 675 | 708 | 741 | 774 | 776 | 809 | 842 | 875 | 908 | 941 | 14 | 47 | 80 | 561 | 114 | 147 | 180 | 213 | 246 | 279 | 281 | 314 | 347 | 380 | 413 | 446 | 494 | 511 | 544 | |
| 20 | 641 | 674 | 707 | 740 | 773 | 806 | 808 | 841 | 874 | 907 | 940 | 13 | 46 | 79 | 112 | 593 | 146 | 179 | 212 | 245 | 278 | 280 | 313 | 346 | 379 | 412 | 445 | 493 | 510 | 543 | 576 | |
| 21 | 673 | 706 | 739 | 772 | 805 | 807 | 840 | 873 | 906 | 939 | 12 | 45 | 78 | 111 | 144 | 625 | 178 | 211 | 244 | 277 | 310 | 312 | 345 | 378 | 411 | 444 | 492 | 509 | 542 | 575 | 608 | |
| 22 | 705 | 738 | 771 | 804 | 837 | 839 | 872 | 905 | 938 | 11 | 44 | 77 | 110 | 143 | 176 | 657 | 210 | 243 | 276 | 309 | 311 | 344 | 377 | 410 | 443 | 491 | 508 | 541 | 574 | 607 | 640 | |
| 23 | 737 | 770 | 803 | 836 | 838 | 871 | 904 | 937 | 10 | 43 | 76 | 109 | 142 | 175 | 208 | 689 | 242 | 275 | 308 | 341 | 343 | 376 | 409 | 442 | 490 | 507 | 540 | 573 | 606 | 639 | 672 | |
| 24 | 769 | 802 | 835 | 868 | 870 | 903 | 936 | 9 | 42 | 75 | 108 | 141 | 174 | 207 | 240 | 721 | 274 | 307 | 340 | 342 | 375 | 408 | 441 | 489 | 506 | 539 | 572 | 605 | 638 | 671 | 704 | |
| 25 | 801 | 834 | 867 | 869 | 902 | 935 | 8 | 41 | 74 | 107 | 140 | 173 | 206 | 239 | 272 | 753 | 306 | 339 | 372 | 374 | 407 | 440 | 488 | 505 | 538 | 571 | 604 | 637 | 670 | 703 | 736 | |
| 26 | 833 | 866 | 899 | 901 | 934 | 7 | 40 | 73 | 106 | 139 | 172 | 205 | 238 | 271 | 304 | 785 | 338 | 371 | 373 | 406 | 439 | 487 | 504 | 537 | 570 | 603 | 636 | 669 | 702 | 735 | 768 | |
| 27 | 865 | 898 | 900 | 933 | 6 | 39 | 72 | 105 | 138 | 171 | 204 | 237 | 270 | 303 | 336 | 817 | 370 | 403 | 405 | 438 | 486 | 503 | 536 | 569 | 602 | 635 | 668 | 701 | 734 | 767 | 800 | |
| 28 | 897 | 930 | 932 | 5 | 38 | 71 | 104 | 137 | 170 | 203 | 236 | 269 | 302 | 335 | 368 | 849 | 402 | 404 | 437 | 485 | 502 | 535 | 568 | 601 | 634 | 667 | 700 | 733 | 766 | 799 | 832 | |
| 29 | 929 | 931 | 4 | 37 | 70 | 103 | 136 | 169 | 202 | 235 | 268 | 301 | 334 | 367 | 400 | 881 | 434 | 436 | 484 | 501 | 534 | 567 | 600 | 633 | 666 | 699 | 732 | 765 | 798 | 831 | 864 | |
| 30 | 961 | 3 | 36 | 69 | 102 | 135 | 168 | 201 | 234 | 267 | 300 | 333 | 366 | 399 | 432 | 913 | 435 | 483 | 500 | 533 | 566 | 599 | 632 | 665 | 698 | 731 | 764 | 797 | 830 | 863 | 896 | |
| 31 | 2 | 35 | 68 | 101 | 134 | 167 | 200 | 233 | 266 | 299 | 332 | 365 | 398 | 431 | 464 | 945 | 482 | 499 | 532 | 565 | 598 | 631 | 664 | 697 | 730 | 763 | 796 | 829 | 862 | 895 | 928 |
Instead of shifting all rows in one direction and all columns in another, you can shift each half of the table in opposite directions (always skipping the middle row or column). This produces the same result using a mirror-symmetry pattern.
Alternative Approach: Bidirectional Shifting
Initial square with numbers 1 -
n2 in
sequence
![]() |
||||||
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | 32 | 33 | 34 | 35 |
| 36 | 37 | 38 | 39 | 40 | 41 | 42 |
| 43 | 44 | 45 | 46 | 47 | 48 | 49 |
|
||||||
After the first pass: Notice how each column is equal to
Σ
![]() |
2 | 3 | 4 | 5 | 6 | 7 | 1 | ![]() |
| 10 | 11 | 12 | 13 | 14 | 8 | 9 | ||
| 18 | 19 | 20 | 21 | 15 | 16 | 17 | ||
| 22 | 23 | 24 | 25 | 26 | 27 | 28 | ||
| 33 | 34 | 35 | 29 | 30 | 31 | 32 | ||
| 41 | 42 | 36 | 37 | 38 | 39 | 40 | ||
| 49 | 43 | 44 | 45 | 46 | 47 | 48 |
Second pass completed: Now each row is also equal to Σ. The Magic Square is ready!
| 10 | 19 | 24 | 5 | 30 | 39 | 48 |
| 18 | 23 | 35 | 13 | 38 | 47 | 1 |
| 22 | 34 | 36 | 21 | 46 | 7 | 9 |
| 33 | 42 | 44 | 25 | 6 | 8 | 17 |
| 41 | 43 | 4 | 29 | 14 | 16 | 28 |
| 49 | 3 | 12 | 37 | 15 | 27 | 32 |
| 2 | 11 | 20 | 45 | 26 | 31 | 40 |
Universal Closed-Form Formula
In addition to the algorithmic construction method described above, the Mamzeris Method includes a universal closed-form formula that directly computes the value at any cell position without performing iterative shifts. This formula is set out in my paper, Universal Closed-Form Construction for Odd-Order Magic Squares (The Mamzeris Method).
Key advantages of the closed-form formula:
- Direct computation: Calculate any individual cell value without constructing the entire square
- Computational efficiency: Ideal for programming, large squares, or sparse calculations
- Mathematical completeness: Provides explicit mathematical expression for the entire construction
- Validation tool: Verify algorithmic constructions or explore specific patterns
The formula
Given an odd order N ≥ 3 and a position (x, y) with 1 ≤ x, y ≤ N, where x is the column and y is the row, both counted from one:
Note the order. The column shift is undone first, which produces Y, and the row shift is then undone using s(Y), not s(y). The construction shifts the rows first and the columns second, so to find what ends up at a given position the two operations must be undone in the reverse order. This is the single point at which readers most often go wrong.
A full derivation, eight worked examples covering every branch of the shift function, the completed 5 × 5, 7 × 7 and 11 × 11 squares, and the zero-based form of the same result are given in the published paper.
Worked example. The value at column 3, row 4 of a 5 × 5 square:
Reading row 4, column 3 of the completed 5 × 5 square shown further down this page confirms the value 16. Remember that x is the column and y is the row; reading the pair the other way round will give the wrong cell.
The formula has been checked cell by cell against the algorithmic construction for every odd order from 3 to 121 inclusive. Every entry agrees, and every resulting square is a genuine associative magic square. The two approaches are therefore complementary rather than alternative: the algorithm is the better way to understand the construction, and the formula is the better way to compute with it.
Understanding How the Method Works
This section explains the mathematical insight behind why the two-pass transformation creates a magic square of odd order. Understanding the balance of row and column sums reveals the elegance of the method.Key Variables:
n = the square's dimension (for a 7×7 square, n = 7)
M = (n2 + 1)/2 = the middle number (located at the center)
Σ = M×n = the magic constant (target sum for each row, column, and diagonal)
r = distance from the middle row or column
The Balancing Principle:
When we fill the initial square (1) with numbers 1 to n2 in sequence, each row and column has a different sum based on its distance from the center. This creates predictable "weight" imbalances:
For columns:
• Moving left from center: each column's sum = Σ - r×n
• Moving right from center: each column's sum = Σ + r×n
For rows:
• Moving up from center: each row's sum = Σ - (r×n2)
• Moving down from center: each row's sum = Σ + (r×n2)
Pass 1 - Balancing the Rows:
The first pass shifts cells left by increasing amounts (row 1 shifts by 1, row 2 by 2, etc.), skipping the middle row. This creates square (2) where all row sums equal Σ.
The key insight: cells shifted off the left edge wrap to the right, adding exactly the right amount to compensate for each row's initial imbalance. The top row gains +1, the next gains +2, and so on, perfectly counterbalancing the initial deficits.
Pass 2 - Balancing the Columns:
The second pass applies the same logic to columns, shifting cells upward by increasing amounts. This transforms square (2) into square (3), where all column sums also equal Σ, creating a perfect magic square.
Visual Guide to the Tables Below:
Left tables: Show each cell's value relative to n (the algebraic view)
Right tables: Show actual numeric values as the square transforms
Green cells: Display row and column sums (diagonals always equal Σ)
Blue cells: Track the middle row and column positions through both passes
Square (3): The completed magic square with all properties satisfied
![]() |
||||||||||||||||||||
| Σ | 175 | Σ | ||||||||||||||||||
| n-6 | n-5 | n-4 | n-3 | n-2 | n-1 | n | Σ -(3n2) | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 28 | Σ -(3n2) | ||||
| n+1 | n+2 | n+3 | n+4 | n+5 | n+6 | n+7 | Σ -(2n2) | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 77 | Σ -(2n2) | ||||
| n+8 | n+9 | n+10 | n+11 | n+12 | n+13 | n+14 | Σ -(1n2) | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 126 | Σ -(1n2) | ||||
| n+15 | n+16 | n+17 | n+18 | n+19 | n+20 | n+21 | Σ | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 175 | Σ | ||||
| n+22 | n+23 | n+24 | n+25 | n+26 | n+27 | n+28 | Σ +(1n2) | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 224 | Σ +(1n2) | ||||
| n+29 | n+30 | n+31 | n+32 | n+33 | n+34 | n+35 | Σ +(2n2) | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 273 | Σ +(2n2) | ||||
| n+36 | n+37 | n+38 | n+39 | n+40 | n+41 | n+42 | Σ +(3n2) | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 322 | Σ +(3n2) | ||||
| Σ | 175 | Σ | ||||||||||||||||||
| 154 | 161 | 168 | 175 | 182 | 189 | 196 | ||||||||||||||
| Σ -(3n) | Σ -(2n) | Σ -(1n) | Σ | Σ +(1n) | Σ +(2n) | Σ +(3n) | Σ -(3n) | Σ -(2n) | Σ -(1n) | Σ | Σ +(1n) | Σ +(2n) | Σ +(3n) | |||||||
![]() |
||||||||||||||||||||
| Σ | 175 | Σ | ||||||||||||||||||
| n-5 | n-4 | n-3 | n-2 | n-1 | n | n-6 | Σ -(3n2) | 2 | 3 | 4 | 5 | 6 | 7 | 1 | 28 | Σ -(3n2) | ||||
| n+3 | n+4 | n+5 | n+6 | n+7 | n+1 | n+2 | Σ -(2n2) | 10 | 11 | 12 | 13 | 14 | 8 | 9 | 77 | Σ -(2n2) | ||||
| n+11 | n+12 | n+13 | n+14 | n+8 | n+9 | n+10 | Σ -(1n2) | 18 | 19 | 20 | 21 | 15 | 16 | 17 | 126 | Σ -(1n2) | ||||
| n+15 | n+16 | n+17 | n+18 | n+19 | n+20 | n+21 | Σ | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 175 | Σ | ||||
| n+26 | n+27 | n+28 | n+22 | n+23 | n+24 | n+25 | Σ +(1n2) | 33 | 34 | 35 | 29 | 30 | 31 | 32 | 224 | Σ +(1n2) | ||||
| n+34 | n+35 | n+29 | n+30 | n+31 | n+32 | n+33 | Σ +(2n2) | 41 | 42 | 36 | 37 | 38 | 39 | 40 | 273 | Σ +(2n2) | ||||
| n+42 | n+36 | n+37 | n+38 | n+39 | n+40 | n+41 | Σ +(3n2) | 49 | 43 | 44 | 45 | 46 | 47 | 48 | 322 | Σ +(3n2) | ||||
| Σ | 175 | Σ | ||||||||||||||||||
| 175 | 175 | 175 | 175 | 175 | 175 | 175 | ||||||||||||||
| Σ | Σ | Σ | Σ | Σ | Σ | Σ | Σ | Σ | Σ | Σ | Σ | Σ | Σ | |||||||
![]() |
||||||||||||||||||||
| Σ | 175 | Σ | ||||||||||||||||||
| n+3 | n+12 | n+17 | n-2 | n+23 | n+32 | n+41 | Σ | 10 | 19 | 24 | 5 | 30 | 39 | 48 | 175 | Σ | ||||
| n+11 | n+16 | n+28 | n+6 | n+31 | n+40 | n-6 | Σ | 18 | 23 | 35 | 13 | 38 | 47 | 1 | 175 | Σ | ||||
| n+15 | n+27 | n+29 | n+14 | n+39 | n | n+2 | Σ | 22 | 34 | 36 | 21 | 46 | 7 | 9 | 175 | Σ | ||||
| n+26 | n+35 | n+37 | n+18 | n-1 | n+1 | n+10 | Σ | 33 | 42 | 44 | 25 | 6 | 8 | 17 | 175 | Σ | ||||
| n+34 | n+36 | n-3 | n+22 | n+7 | n+9 | n+21 | Σ | 41 | 43 | 4 | 29 | 14 | 16 | 28 | 175 | Σ | ||||
| n+42 | n-4 | n+5 | n+30 | n+8 | n+20 | n+25 | Σ | 49 | 3 | 12 | 37 | 15 | 27 | 32 | 175 | Σ | ||||
| n-5 | n+4 | n+13 | n+38 | n+19 | n+24 | n+33 | Σ | 2 | 11 | 20 | 45 | 26 | 31 | 40 | 175 | Σ | ||||
| Σ | 175 | Σ | ||||||||||||||||||
| 175 | 175 | 175 | 175 | 175 | 175 | 175 | ||||||||||||||
| Σ | Σ | Σ | Σ | Σ | Σ | Σ | Σ | Σ | Σ | Σ | Σ | Σ | Σ |

Variations
The Mamzeris Method is remarkably flexible. From the same starting table it produces four different magic squares of the same order. Two things may be varied, and each has two settings: Every one of the four starts from the same table, the numbers 1 to 25 written in reading order. The colours mark which row of that starting table each number came from, so the movement can be followed by eye. The central row is grey because it never moves. In all four squares every row, every column and both diagonals total 65, and every pair of cells placed symmetrically about the centre totals 26. The four are genuinely different: none is a rotation, a reflection or a transpose of any other.
The same four variations at order 19, with every number shown. Each cell is shaded on a single scale running from red at the lowest values through white at the middle to blue at the highest, so the pattern each variation creates can be seen at a glance. Every row, column and main diagonal in all four squares totals 3,439, and every pair of cells placed symmetrically about the centre totals 362.
Permutations
Beyond the four variations, the method produces many more distinct squares, because the initial table itself may be rearranged before the two shifts are applied. Its rows may be permuted, and so may its columns.
For a 7×7 square that is 48 admissible permutations of the rows and 48 of the columns, so 2,304 different initial tables, each of which produces a different magic square.
P is a unit of measurement rather than a count of anything on its own. Its only purpose is to keep the totals short. The quantity that genuinely counts something is the number of admissible initial tables, and that is exactly four times P, since (2m × m!)² = 4P for every odd n. At order 7, P = 576 and the 2,304 initial tables counted above are 4P.
Order 3 is the exception. There the four families fall on top of one another instead of staying apart, and the true total is 8 rather than 16P. That figure is not a shortcoming. It is every 3×3 magic square that exists, since the 3×3 has exactly one square in eight orientations and nothing else. The method therefore produces all of them.
• The shift directions: rows left with columns up, or rows right with columns down
• The order of the two passes: rows shifted first, or columns shifted first
Two direction settings multiplied by two pass orders give four distinct squares. All four are shown below, first for order 5 and then for order 19.
A warning about the shift directions. Only two of the four possible direction pairs give a magic square: rows left with columns up, and rows right with columns down. The mixed pairs, rows left with columns down and rows right with columns up, do not. They give correct column sums and correct diagonal sums, and the result is still associative, so a partial check appears to pass. The row sums are wrong. Anyone verifying the method must check the rows as well as the columns.
The order of the two passes. Shifting the rows first and then the columns gives one square. Shifting the columns first and then the rows gives a genuinely different square. This is the second source of variation, and combined with the two working direction pairs it accounts for all four squares.
The two pass orders are not related to one another by any rotation or reflection. Verified by enumeration at orders 5, 7 and 9, the square obtained by shifting the columns first never appears among the eight rotations and reflections of the square obtained by shifting the rows first.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 8 12 4 17 24 11 20 10 23 1 19 21 13 5 7 25 3 16 6 15 2 9 22 14 18 22 19 2 14 8 5 23 6 16 15 9 1 13 25 17 11 10 20 3 21 18 12 24 7 4 12 3 19 25 6 8 24 5 11 17 16 22 13 4 10 9 15 21 2 18 20 1 7 23 14 10 21 17 3 14 19 15 1 22 8 6 2 13 24 20 18 4 25 11 7 12 23 9 5 16 22 43 64 85 106 127 148 169 180 11 192 213 234 255 276 297 318 339 360 42 63 84 105 126 147 168 179 209 31 212 233 254 275 296 317 338 359 1 62 83 104 125 146 167 178 208 210 51 232 253 274 295 316 337 358 19 21 82 103 124 145 166 177 207 228 230 71 252 273 294 315 336 357 18 20 41 102 123 144 165 176 206 227 229 250 91 272 293 314 335 356 17 38 40 61 122 143 164 175 205 226 247 249 270 111 292 313 334 355 16 37 39 60 81 142 163 174 204 225 246 248 269 290 131 312 333 354 15 36 57 59 80 101 162 173 203 224 245 266 268 289 310 151 332 353 14 35 56 58 79 100 121 172 202 223 244 265 267 288 309 330 171 352 13 34 55 76 78 99 120 141 201 222 243 264 285 287 308 329 350 181 12 33 54 75 77 98 119 140 161 221 242 263 284 286 307 328 349 10 191 32 53 74 95 97 118 139 160 190 241 262 283 304 306 327 348 9 30 211 52 73 94 96 117 138 159 189 200 261 282 303 305 326 347 8 29 50 231 72 93 114 116 137 158 188 199 220 281 302 323 325 346 7 28 49 70 251 92 113 115 136 157 187 198 219 240 301 322 324 345 6 27 48 69 90 271 112 133 135 156 186 197 218 239 260 321 342 344 5 26 47 68 89 110 291 132 134 155 185 196 217 238 259 280 341 343 4 25 46 67 88 109 130 311 152 154 184 195 216 237 258 279 300 361 3 24 45 66 87 108 129 150 331 153 183 194 215 236 257 278 299 320 2 23 44 65 86 107 128 149 170 351 182 193 214 235 256 277 298 319 340 344 327 310 293 276 259 242 225 208 9 182 155 138 121 104 87 70 53 36 19 345 328 311 294 277 260 243 226 27 191 183 156 139 122 105 88 71 54 37 1 346 329 312 295 278 261 244 45 228 192 184 157 140 123 106 89 72 55 38 2 347 330 313 296 279 262 63 246 210 193 185 158 141 124 107 90 73 56 20 3 348 331 314 297 280 81 264 247 211 194 186 159 142 125 108 91 74 57 21 4 349 332 315 298 99 282 265 229 212 195 187 160 143 126 109 92 75 39 22 5 350 333 316 117 300 283 266 230 213 196 188 161 144 127 110 93 76 40 23 6 351 334 135 318 301 284 248 231 214 197 189 162 145 128 111 94 58 41 24 7 352 153 336 319 302 285 249 232 215 198 190 163 146 129 112 95 59 42 25 8 181 354 337 320 303 267 250 233 216 199 172 164 147 130 113 77 60 43 26 209 10 355 338 321 304 268 251 234 217 200 173 165 148 131 114 78 61 44 227 28 11 356 339 322 286 269 252 235 218 201 174 166 149 132 96 79 62 245 46 29 12 357 340 323 287 270 253 236 219 202 175 167 150 133 97 80 263 64 47 30 13 358 341 305 288 271 254 237 220 203 176 168 151 115 98 281 82 65 48 31 14 359 342 306 289 272 255 238 221 204 177 169 152 116 299 100 83 66 49 32 15 360 324 307 290 273 256 239 222 205 178 170 134 317 118 101 84 67 50 33 16 361 325 308 291 274 257 240 223 206 179 171 335 136 119 102 85 68 51 34 17 343 326 309 292 275 258 241 224 207 180 353 154 137 120 103 86 69 52 35 18 40 60 80 100 120 140 160 180 10 201 221 241 261 281 301 321 341 361 20 79 99 119 139 159 179 199 29 220 240 260 280 300 320 340 360 19 39 59 118 138 158 178 198 218 48 239 259 279 299 319 339 359 18 38 58 78 98 157 177 197 217 237 67 258 278 298 318 338 358 17 37 57 77 97 117 137 196 216 236 256 86 277 297 317 337 357 16 36 56 76 96 116 136 156 176 235 255 275 105 296 316 336 356 15 35 55 75 95 115 135 155 175 195 215 274 294 124 315 335 355 14 34 54 74 94 114 134 154 174 194 214 234 254 313 143 334 354 13 33 53 73 93 113 133 153 173 193 213 233 253 273 293 162 353 12 32 52 72 92 112 132 152 172 192 212 232 252 272 292 312 332 191 211 231 251 271 291 311 331 351 181 11 31 51 71 91 111 131 151 171 30 50 70 90 110 130 150 170 190 210 230 250 270 290 310 330 350 9 200 69 89 109 129 149 169 189 209 229 249 269 289 309 329 349 8 28 219 49 108 128 148 168 188 208 228 248 268 288 308 328 348 7 27 47 238 68 88 147 167 187 207 227 247 267 287 307 327 347 6 26 46 66 257 87 107 127 186 206 226 246 266 286 306 326 346 5 25 45 65 85 276 106 126 146 166 225 245 265 285 305 325 345 4 24 44 64 84 104 295 125 145 165 185 205 264 284 304 324 344 3 23 43 63 83 103 123 314 144 164 184 204 224 244 303 323 343 2 22 42 62 82 102 122 142 333 163 183 203 223 243 263 283 342 1 21 41 61 81 101 121 141 161 352 182 202 222 242 262 282 302 322 38 343 325 307 289 271 253 235 217 199 10 182 164 146 128 110 92 74 56 75 57 1 344 326 308 290 272 254 236 218 29 201 183 165 147 129 111 93 112 94 76 20 2 345 327 309 291 273 255 237 48 220 202 184 166 148 130 149 131 113 95 39 21 3 346 328 310 292 274 256 67 239 221 203 185 167 186 168 150 132 114 58 40 22 4 347 329 311 293 275 86 258 240 222 204 223 205 187 169 151 133 77 59 41 23 5 348 330 312 294 105 277 259 241 260 242 224 206 188 170 152 96 78 60 42 24 6 349 331 313 124 296 278 297 279 261 243 225 207 189 171 115 97 79 61 43 25 7 350 332 143 315 334 316 298 280 262 244 226 208 190 134 116 98 80 62 44 26 8 351 162 153 135 117 99 81 63 45 27 9 181 353 335 317 299 281 263 245 227 209 200 11 354 336 318 300 282 264 246 228 172 154 136 118 100 82 64 46 28 47 219 30 12 355 337 319 301 283 265 247 191 173 155 137 119 101 83 65 84 66 238 49 31 13 356 338 320 302 284 266 210 192 174 156 138 120 102 121 103 85 257 68 50 32 14 357 339 321 303 285 229 211 193 175 157 139 158 140 122 104 276 87 69 51 33 15 358 340 322 304 248 230 212 194 176 195 177 159 141 123 295 106 88 70 52 34 16 359 341 323 267 249 231 213 232 214 196 178 160 142 314 125 107 89 71 53 35 17 360 342 286 268 250 269 251 233 215 197 179 161 333 144 126 108 90 72 54 36 18 361 305 287 306 288 270 252 234 216 198 180 352 163 145 127 109 91 73 55 37 19 324

Not every rearrangement is allowed. The finished square must be associative, which means that any two cells placed symmetrically about the centre must add up to n² + 1. That holds only if the permutation preserves the central pairing, so that row i and row n + 1 − i stay together as a pair and the middle row stays in the middle. The same condition applies to the columns. A permutation that meets it is called admissible. Every admissible pair of permutations, one for the rows and one for the columns, yields a valid associative magic square, and no two pairs yield the same square.
How many admissible permutations are there
Write m = (n − 1) / 2 for the number of pairs on either side of the centre. Each pair may be placed in any of m positions and either way round, which gives 2m × m! admissible permutations along a single axis. Applying this independently to the rows and to the columns squares that figure:
The unit P
The published papers carry a single symbol, P, so that the various totals can be written compactly. It is defined as:
The rising ladder
Every square in the three steps below is a different square. Nothing is merged, and nothing is treated as equivalent to anything else. If the squares were printed on paper and laid side by side, no two would look the same.
4P — one setting. Fix the pass order, say the rows are shifted first, and fix the direction, say rows to the left and columns upwards. Running every admissible initial table through that one setting gives 4P squares. At order 7 that is 2,304.
8P — both working directions. Keep the same pass order but allow both of the direction pairs that work, rows left with columns up, and rows right with columns down. The two sets have no square in common, so the count doubles. At order 7 that is 4,608.
16P — both pass orders as well. Now allow the columns to be shifted before the rows as well as after. Again the new set shares no square with the old one, so the count doubles a second time. At order 7 that is 9,216.
In one line, the factor of sixteen is:
4P admissible initial tables × 2 working shift directions × 2 pass orders = 16P
So 16P is the complete number of distinct magic squares the Mamzeris Method can construct at any odd order from 5 upwards. The four families are entirely separate: none of the six possible overlaps between them contains a single square. Every figure in the table below has been confirmed by exhaustive enumeration at orders 5, 7 and 9.
A note on reading the paper alongside this page. Earlier releases of the closed-form paper give these counts for the rows-first pass order only, and they treat a square and its mirror image as one square. Under that convention the same results read 4P and 8P. This page counts every square that looks different on paper, and it admits both pass orders, which is why the total here is 16P. The two are not in conflict. They answer different questions, and the ladder above is the complete one.
Order P
(the unit)4P
one setting8P
both directions16P
complete total5×5 16 64 128 256 7×7 576 2,304 4,608 9,216 9×9 36,864 147,456 294,912 589,824 11×11 3,686,400 14,745,600 29,491,200 58,982,400 13×13 530,841,600 2,123,366,400 4,246,732,800 8,493,465,600 15×15 104,044,953,600 416,179,814,400 832,359,628,800 1,664,719,257,600 17×17 26,635,508,121,600 106,542,032,486,400 213,084,064,972,800 426,168,129,945,600 19×19 8,629,904,631,398,400 34,519,618,525,593,600 69,039,237,051,187,200 138,078,474,102,374,400
Two things that are deliberately not counted
Rearranging a finished square. Permuting the rows and columns of a square that has already been built is a different operation from permuting the initial table, and it is not part of the method. Almost none of the squares it produces can be built by the method at all, so they do not belong in the total. The two families are printed side by side in the published paper so the difference can be seen directly.
Filling the initial table down the columns. Writing 1 to n² down the columns instead of across the rows does produce further magic squares, but they turn out to be nothing more than the 16P squares reflected along the main diagonal. They are the same squares viewed sideways, so counting them would be counting twice.
Rearrangements that break the central pairing occasionally still give a magic square, but never an associative one, and the number of them follows no regular pattern from one order to the next. Associativity is a defining property of the method, so these are excluded.
Twelve examples at order 7 follow, each produced by permuting the rows and the columns of the initial table and then applying the two shifts. These are members of the 4P family counted above. The first is the plain case, with the initial table left in reading order. Cells are shaded by the row of the initial table each number came from, so the effect of the permutation can be followed by eye. Every square shown is a genuine associative magic square with all lines totalling 175.
10 19 24 5 30 39 48 18 23 35 13 38 47 1 22 34 36 21 46 7 9 33 42 44 25 6 8 17 41 43 4 29 14 16 28 49 3 12 37 15 27 32 2 11 20 45 26 31 40 12 17 26 3 30 39 48 18 23 29 13 40 45 7 28 34 42 15 46 1 9 31 36 44 25 6 14 19 41 49 4 35 8 16 22 43 5 10 37 21 27 32 2 11 20 47 24 33 38 38 33 24 5 16 11 48 32 23 21 41 10 47 1 22 20 8 35 46 7 37 19 14 44 25 6 36 31 13 43 4 15 42 30 28 49 3 40 9 29 27 18 2 39 34 45 26 17 12 41 30 27 44 19 11 3 32 26 21 38 13 2 43 22 17 8 35 4 49 40 16 14 5 25 45 36 34 10 1 46 15 42 33 28 7 48 37 12 29 24 18 47 39 31 6 23 20 9 17 12 24 47 37 32 6 11 23 42 20 31 5 43 22 41 29 14 4 49 16 40 35 2 25 48 15 10 34 1 46 36 21 9 28 7 45 19 30 8 27 39 44 18 13 3 26 38 33 10 19 24 5 29 39 49 18 22 30 14 38 47 6 27 35 41 16 46 2 8 33 37 43 25 7 13 17 42 48 4 34 9 15 23 44 3 12 36 20 28 32 1 11 21 45 26 31 40 20 37 27 2 10 32 47 39 24 14 19 34 44 1 22 12 29 42 46 7 17 9 35 45 25 5 15 41 33 43 4 8 21 38 28 49 6 16 31 36 26 11 3 18 40 48 23 13 30 3 33 24 12 16 46 41 32 23 15 6 45 40 14 28 20 49 29 39 8 2 19 43 37 25 13 7 31 48 42 11 21 1 30 22 36 10 5 44 35 27 18 9 4 34 38 26 17 47 15 7 22 14 47 32 38 4 26 44 17 29 42 13 27 45 34 2 39 9 19 49 30 40 25 10 20 1 31 41 11 48 16 5 23 37 8 21 33 6 24 46 12 18 3 36 28 43 35 41 16 27 2 31 11 47 18 24 29 40 13 44 7 28 33 14 15 46 1 38 30 8 45 25 5 42 20 12 49 4 35 36 17 22 43 6 37 10 21 26 32 3 39 19 48 23 34 9 3 40 24 19 13 46 30 39 27 8 2 45 33 21 28 9 49 36 32 15 6 12 43 34 25 16 7 38 44 35 18 14 1 41 22 29 17 5 48 42 23 11 20 4 37 31 26 10 47 10 47 24 19 7 39 29 46 28 2 8 38 33 20 27 1 41 44 32 16 14 5 37 35 25 15 13 45 36 34 18 6 9 49 23 30 17 12 42 48 22 4 21 11 43 31 26 3 40
Rotations and Reflections
This section answers the question every reader asks next. If the method builds 16P squares, surely turning them round and mirroring them produces still more. The answer is no, and the reason is worth seeing.
Any magic square can be turned through a quarter, a half or three quarters of a turn, and each of those can be mirrored, giving eight orientations in all. Every one of them is still a magic square, because rotating or mirroring a grid moves whole rows, columns and diagonals about without changing what is in them. The four rotations of the 3×3 square are shown below.
| 4 | 3 | 8 | 8 | 1 | 6 | |
| 9 | 5 | 1 | 3 | 5 | 7 | |
| 2 | 7 | 6 | 4 | 9 | 2 | |
![]() |
||||||
| 6 | 7 | 2 | 2 | 9 | 4 | |
| 1 | 5 | 9 | 7 | 5 | 3 | |
| 8 | 3 | 4 | 6 | 1 | 8 |
What the orientations do to a Mamzeris square
Apply all eight orientations to every one of the 16P squares and a sharp division appears. Four of the eight always land back on a square the method already builds. The other four always land on a square the method cannot build at all. There are no exceptions and no borderline cases. This has been checked on every square at orders 5, 7 and 9.
| Orientation | Result | Already in the 16P total? |
|---|---|---|
| Leave as it is | a Mamzeris square | Yes |
| Turn a half turn (180°) | a Mamzeris square | Yes |
| Mirror left to right | a Mamzeris square | Yes |
| Mirror top to bottom | a Mamzeris square | Yes |
| Turn a quarter turn (90°) | a magic square, but not one of ours | No |
| Turn three quarters (270°) | a magic square, but not one of ours | No |
| Reflect along the main diagonal | a magic square, but not one of ours | No |
| Reflect along the other diagonal | a magic square, but not one of ours | No |
Why the first four cannot escape. Turning an associative square through a half turn produces exactly its complement, the square in which every value v has been replaced by n² + 1 − v. That follows straight from associativity, because the value opposite any cell is already its complement, and the half turn is what brings it into place. The method always builds a square together with its complement, so the half turn has nowhere new to go. Mirroring behaves in a similar way: it carries the left-and-up family onto the right-and-down family, and both are inside the total already. The two mirrors and the half turn between them account for the whole of that group.
Why the other four fall outside. A quarter turn, or a reflection along a diagonal, interchanges the roles of the rows and the columns. The method treats the two axes differently, one shifted before the other, so the result is a magic square built by some other means, not by this construction. Not one square out of the 9,216 at order 7 survives a quarter turn and stays in the set.
The consequence for the total. Rotations and reflections add nothing. Four of them are already counted and the other four produce squares outside the method, which the method does not claim. The total stands at 16P.
Order 3 once more. At order 3 all eight orientations stay inside, because the total there is 8 and that is every 3×3 magic square in existence. The 3×3 is the only order at which the eight orientations and the method's own total are the same thing, which is why it makes a clear picture but a misleading rule.
The four variations are not orientations. This is worth stating plainly, because the two ideas are easy to confuse. The orientations above are applied to a square that is already finished, and they work on any magic square ever written down. The four variations of the Mamzeris Method come from the construction itself, from the shift directions and the order of the two passes. The four are genuinely different squares: none of them is a rotation, a reflection or a diagonal reflection of any other. That has been checked at orders 5, 7, 11, 19 and 31.
For any comments or questions, please email me at contact@oddmagicsquares.com
Smaragdos (Marios) Mamzeris - Magic Squares






