How many essentially distinct normal $4\times4$ magic squares have all $2\times2$ subsquares sum to the magic constant?

Relevant information

I apologize if this basic question has already been asked here before. A $4\times4$ most-perfect magic square is a magic square which is normal (contains the integers $1,2,3,...,16$) and for which:

$(1)$ All pairs of integers distant by $2$ positions along any diagonal sum to $17$, and

$(2)$ Each of the $9$ $2\times2$ subsquares sums to the magic constant ($34$)

I want to know how many $4\times4$ magic squares satisfy property $(2)$ with or without $(1)$. Wikipedia says there are $48$ unique most-perfect $4\times4$ magic squares. It also says that all $4\times4$ panmagic squares (magic square where the broken diagonals all add up to the magic constant) are most-perfect (and obviously all most-perfect squares are panmagic), but I'm not sure if there are $4\times4$ magic squares that satisfy $(2)$ but are not panmagic. I have tried (and failed) to produce such a square by hand. An example of a $4\times4$ magic square satisfying $(2)$ is shown below.

Thus my question is: How many essentially distinct normal $4\times4$ magic squares are there that satisfy $(2)$? Are there only $48$ (the most-perfect/panmagic squares) or are some such squares not most-perfect/panmagic?

$4\times4$ most-perfect magic square:

$\hskip2in$Magic square

  • $\begingroup$ This is a bit confusing in that the article on "panmagic" that you link to defines it as something you never mention in the post ("the diagonals that wrap round at the edges of the square also add up to the magic constant"). Thus you seem to be asking two different questions: "I want to know how many 4×4 magic squares satisfy property (2) with or without (1)" and "Thus my question is: How many essentially distinct normal 4×4 magic squares are there that satisfy (2)? Are there only 48 or are some such squares not panmagic?" Please clarify. $\endgroup$
    – joriki
    Apr 17, 2020 at 10:40
  • $\begingroup$ @joriki I'm not sure where your confusion lies... My question is how many essentially distinct normal $4\times4$ magic squares satisfy $(2)$. The relevance of panmagic squares is that all $4\times4$ most-perfect squares are panmagic (and vice versa - not true for greater $n$), and these squares satisfy $(2)$ and we know there are $48$ such squares. Thus asking how many essentially distinct normal $4\times4$ magic squares satisfy $(2)$ is the same as asking whether there are $4\times4$ magic squares satisfying $(2)$ apart from the $48$ panmagic (and most-perfect) squares. $\endgroup$
    – Anon
    Apr 17, 2020 at 11:17
  • 1
    $\begingroup$ I've edited the question to hopefully clarify exactly what I'm asking, Please let me know if there is anything else I should change. $\endgroup$
    – Anon
    Apr 17, 2020 at 11:26
  • $\begingroup$ It's much clearer now, thanks. Would you be interested in a solution by computer search? $\endgroup$
    – joriki
    Apr 17, 2020 at 11:28
  • $\begingroup$ @joriki While it would be interesting if there were a neat mathematical argument for the number of solutions, I'd be happy with a computer-assisted solution. I don't really have the programming wherewithal to find such a solution myself. $\endgroup$
    – Anon
    Apr 17, 2020 at 11:43

2 Answers 2


After some further thought, I've realised why Joriki's answer is correct (i.e. why all $4\times4$ magic squares satisfying $(2)$ are panmagic and most-perfect). It's too long to put in a comment, so I've put it in an answer here.

1. $(2)$ implies panmagicness

Let us take an arbitrary magic square satisfying property $(2)$ and label the elements $a_{m,n}$ where $m\in\{0,1,2,3\}$ is the row number and $n\in\{0,1,2,3\}$ is the column number.

By the definition of a magic square, we have:

$$\sum_{k=0}^3 a_{k,n}=34~~~~\forall n$$ $$\sum_{k=0}^3 a_{m,k}=34~~~~\forall m$$ $$\sum_{k=0}^3 a_{k,k}=34$$ $$\sum_{k=0}^3 a_{k,4-k}=34$$

The first observation is that if $(2)$ holds for all $9$ subsquares, then it also holds for every 'broken' subsquare that wraps around the edges and corners. To see this, extend the square like a torus, to fill an infinite two-dimensional grid with repeating copies of the original magic square (so that for instance $a_{0,3}$ occurs to the left of $a_{0,0}$ and so on). Then obviously all $2\times2$ subsquares that are wholly within each copy of the original square sum to $34$.

First we consider $2\times2$ subsquares that only wrap around one edge between adjacent magic squares (e.g. $a_{0,0},a_{0,1},a_{3,0},a_{3,1}$ or $a_{1,0},a_{2,0},a_{1,3},a_{2,3}$). Without loss of generality, let this be a horizontal edge. Without loss of generality, let this subsquare be $a_{0,0},a_{0,1},a_{3,0},a_{3,1}$. Then by $(2)$ we have $a_{0,0}+a_{0,1}+a_{1,0}+a_{1,1}=a_{1,0}+a_{1,1}+a_{2,0}+a_{2,1}=a_{2,0}+a_{2,1}+a_{3,0}+a_{3,1}=34$, and if we subtract the centre square from the sum of the two other squares we see that: $$a_{0,0}+a_{0,1}+a_{3,0}+a_{3,1}\\=a_{0,0}+a_{0,1}+a_{1,0}+a_{1,1}-a_{1,0}-a_{1,1}-a_{2,0}-a_{2,1}+a_{2,0}+a_{2,1}+a_{3,0}+a_{3,1}=34$$ This argument may be generalized to show that any $2\times2$ subsquare wrapping around a single horizontal or vertical edge of the magic square has sum $34$.

There is a single $2\times2$ subsquare wrapping around both horizontal and vertical edges, namely $a_{0,0},a_{0,3},a_{3,0},a_{3,3}$. It follows from our previous result and from the fact that the sum of each row is $34$ that: $$a_{0,0}+a_{0,3}+a_{3,0}+a_{3,3}\\=a_{0,0}+a_{0,1}+a_{0,2}+a_{0,3}+a_{3,0}+a_{3,1}+a_{3,2}+a_{3,3}-(a_{0,1}+a_{0,2}+a_{3,1}+a_{3,2})\\=34+34-34=34$$

Thus if all $9$ $2\times2$ subsquares sum to $34$, then every $2\times2$ subsquare on our infinite grid of copies of the magic square sums to $34$. This can be stated:

$$a_{j\pmod 4,k\pmod4}+a_{j\pmod 4,k+1\pmod4}+a_{j+1\pmod 4,k\pmod4}+a_{j+1\pmod 4,k+1\pmod4}=34~~~\forall j,k$$

Now note that: $$a_{j\pmod 4,k\pmod4}+a_{j\pmod 4,k+1\pmod4}+a_{j+1\pmod 4,k\pmod4}+a_{j+1\pmod 4,k+1\pmod4}=34=a_{j+1\pmod 4,k\pmod4}+a_{j+1\pmod 4,k+1\pmod4}+a_{j+2\pmod 4,k\pmod4}+a_{j+2\pmod 4,k+1\pmod4}$$

This demonstrates the first of the following $2$ identities:

$$a_{j\pmod 4,k\pmod4}+a_{j\pmod 4,k+1\pmod4}\\=a_{j+2\pmod 4,k\pmod4}+a_{j+2\pmod 4,k+1\pmod4}~~~\forall j,k\tag{c}$$ $$a_{j\pmod 4,k\pmod4}+a_{j+1\pmod 4,k\pmod4}\\=a_{j\pmod 4,k+2\pmod4}+a_{j+1\pmod 4,k+2\pmod4}~~~\forall j,k\tag{d}$$

The second identity follows by an analogous argument. Now note that: $$a_{j\pmod 4,k\pmod4}+a_{j+1\pmod 4,k\pmod4}\\=a_{j\pmod 4,k+2\pmod4}+a_{j+1\pmod 4,k+2\pmod4}~~~\forall j,k$$ and $$a_{j+1\pmod 4,k\pmod4}+a_{j+2\pmod 4,k\pmod4}\\=a_{j+1\pmod 4,k+2\pmod4}+a_{j+2\pmod 4,k+2\pmod4}~~~\forall j,k$$ Therefore: $$a_{j+1\pmod 4,k\pmod4}=a_{j\pmod 4,k+2\pmod4}+a_{j+1\pmod 4,k+2\pmod4}-a_{j\pmod 4,k\pmod4}\therefore~~a_{j\pmod 4,k+2\pmod4}+a_{j+1\pmod 4,k+2\pmod4}-a_{j\pmod 4,k\pmod4}+a_{j+2\pmod 4,k\pmod4}\\=a_{j+1\pmod 4,k+2\pmod4}+a_{j+2\pmod 4,k+2\pmod4}$$ Which implies: $$a_{j\pmod 4,k\pmod4}+a_{j+2\pmod 4,k+2\pmod4}\\=a_{j\pmod 4,k+2\pmod4}+a_{j+2\pmod 4,k\pmod4}~~~\forall j,k$$ In other words, for every $3\times3$ subsquare, the pairs of diagonally opposing corners have the same sum.

We may now prove that the square is panmagic. This is equivalent to showing that the following two equations hold: $$a_{j\pmod 4,k\pmod4}+a_{j+1\pmod 4,k+1\pmod4}\\+a_{j+2\pmod 4,k+2\pmod4}+a_{j+3\pmod 4,k+3\pmod4}=34~~~\forall j,k\tag{a}$$ $$a_{j\pmod 4,k+3\pmod4}+a_{j-1\pmod 4,k+2\pmod4}\\+a_{j-2\pmod 4,k+1\pmod4}+a_{j-3\pmod 4,k\pmod4}=34~~~\forall j,k\tag{b}$$ Without loss of generality, we will prove $(a)$ and $(b)$ for $j=0$ and the method of proof will easily generalize to other $j$. Thus we need to show: $$a_{0,k\pmod4}+a_{1,k+1\pmod4}+a_{2,k+2\pmod4}+a_{3,k+3\pmod4}=34~~~\forall k\tag{a*}$$ $$a_{0,k+3\pmod4}+a_{1,k+2\pmod4}+a_{2,k+1\pmod4}+a_{3,k\pmod4}=34~~~\forall k\tag{b*}$$ Both identities hold for $k=0$ by the definition of a magic square. But for every $3\times3$ subsquare, the pairs of diagonally opposing corners have the same sum, so we have that: $$a_{0,0}+a_{1,1}+a_{2,2}+a_{3,3}=34\\\therefore~~a_{0,2}+a_{1,3}+a_{2,0}+a_{3,1}=34$$ which implies $(a*)$ for $k=2$. Analogously, $(b*)$ holds for $k=2$. But similar reasoning shows: $$a_{0,3}+a_{1,2}+a_{2,1}+a_{3,0}=34\\\therefore~~a_{0,1}+a_{1,2}+a_{2,3}+a_{3,0}=34$$ which implies $(a*)$ for $k=1$. Similarly, $$a_{0,3}+a_{1,2}+a_{2,1}+a_{3,0}=34\\\therefore~~a_{0,3}+a_{1,0}+a_{2,1}+a_{3,2}=34$$ which implies $(a*)$ for $k=3$. Analogous reasoning demonstrates $(b*)$ for $k=1,3$. Our result may trivially be extended to other $j$ to demonstrate that $(a)$ and $(b)$ hold which implies that our square is panmagic.

Thus every $4\times4$ normal magic square whose $9$ $2\times2$ subsquares sum to $34$ is panmagic.

2. Panmagicness implies $(2)$

Before we demonstrate that every panmagic square satisfies $(1)$ let us show that all panmagic squares satisfy $(2)$ which will enable us to understand the unproved assumption in the question that all panmagic squares are most-perfect.

Let us pick an arbitrary $4\times4$ normal magic square which is panmagic (i.e. satisfies $(a)$ and $(b)$). We simply need to demonstrate that the $9$ $2\times2$ subsquares sum to $34$.

Applying $(a)$ and $(b)$ allows us to deduce that:


Similarly applying the row property of a magic square we have trivially that:


This implies that:

$$a_{0,0}+a_{0,1}+a_{1,0}+a_{1,1}+a_{0,2}+a_{0,3}+a_{1,2}+a_{1,3}\\=a_{0,0}+a_{0,1}+a_{1,0}+a_{1,1}+a_{2,2}+a_{2,3}+a_{3,2}+a_{3,3}\\\therefore a_{0,2}+a_{0,3}+a_{1,2}+a_{1,3}=a_{2,2}+a_{2,3}+a_{3,2}+a_{3,3}$$

But the column property of magic squares trivially gives us:


enabling us to conclude that: $$a_{0,2}+a_{0,3}+a_{1,2}+a_{1,3}=34$$

A directly analogous process enables us to show that each of the $4$ corner $2\times2$ subsquares sums to $34$. It is a simple exercise to extend this same reasoning to each of the other $5$ subsquares using the translational symmetry of the panmagic square in the toroidal grid.

Thus every $4\times4$ panmagic square satisfies $(2)$, which implies in conjunction with our previous result that a $4\times4$ normal magic square is panmagic $\text{iff}$ it satisfies $(2)$.

3. $(2)$ implies $(1)$

We must now prove that every square satisfying $(2)$ also satisfies $(1)$. First note that because the square is of size $4$, for any $a_{m,n}$ there exists a unique element $p(a_{m,n})=a_{m+2\pmod 4,n+2\pmod4}$ located $2$ squares away diagonally in any direction. For any $a_{m,n}$, define $s(a_{m,n})=a_{m,n}+p(a_{m,n})$.

Now by the definition of a magic square we have:


But applying $(c)$ followed by our result that for every $3\times3$ subsquare, the pairs of diagonally opposing corners have the same sum, we deduce that:

$$a_{0,0}+a_{2,1}+a_{2,2}+a_{0,3}=34\\\therefore a_{0,0}+a_{2,3}+a_{2,2}+a_{0,1}=34\\\therefore s(a_{0,0})+s(a_{0,1})=34$$

Let $s(a_{0,0})=x$ and $s(a_{0,1})=y$ (so $x+y=34$). We can easily generalize this to show: $$s(a_{m,n})+s(a_{m,n+1})+34$$

Now this implies that: $$s(a_{0,3})+s_(a_{0,0})=34=s(a_{0,0})+s_(a_{0,1})\\\therefore s(a_{0,3})=y$$

and similarly we may show that $s(a_{0,2})=x$.

But by definition $s(a_{m,n})=s(p(a_{m,n}))$ so it follows that $s_{2,0}=x$, $s_{2,1}=y$, $s_{2,2}=x$, and $s_{2,3}=y$.

Using the column property of magic squares we have that: $$a_{0,0}+a_{1,0}+a_{2,0}+a_{3,0}=34$$

and using an analogous process to the above it is easy to show that: $$a_{0,0}+a_{1,0}+a_{2,2}+a_{3,2}=34$$

from which we may deduce that $s(a_{1,0})=y$, and this enables us to deduce similarly to the above that $s(a_{1,1})=x$, $s(a_{1,2})=y$, $s(a_{1,3})=x$, $s(a_{3,0})=y$, $s(a_{3,1})=x$, $s(a_{3,2})=y$, and $s(a_{3,3})=x$.

But we may use the diagonal property of the magic square to deduce that:

$$2a_{0,0}+2a_{1,1}+2a_{2,2}+2a_{3,3}=34+34\\\therefore s(a_{0,0})+s(a_{1,1})+s(a_{2,2})+s(a_{3,3})=34+34\\\therefore 2x=34\\\therefore x=y=17\\\therefore s(a_{m,n})=17~~~\forall m,n$$

This is equivalent to $(1)$ and proves that every panmagic $4\times4$ square satisfies $(1)$.

The converse is trivial to show: if a $4\times4$ normal magic square satisfies $(1)$ then it is panmagic

Thus we have proved the following:

  1. A $4\times4$ normal magic square is panmagic $\text{iff}$ all $9$ subsquares sum to $34$
  2. A $4\times4$ normal magic square is panmagic $\text{iff}$ all pairs of squares distant by $2$ along any diagonal sum to $17$

We have therefore shown that the set of all $4\times4$ normal magic squares satisfying $(1)$, the set of all $4\times4$ normal magic squares satisfying $(2)$, the set of all $4\times4$ panmagic squares, and the set of all $4\times4$ most-perfect squares (those satisfying $(1)$ and $(2)$) are identical, and as Joriki kindly demonstrated, there are $48$ of these.

  • $\begingroup$ $+1$. I think you should make this the accepted answer. In the equation following "Then by $(2)$ we have", the indexes are off by $1$. $\endgroup$
    – joriki
    Apr 18, 2020 at 5:33
  • 1
    $\begingroup$ @joriki I might do that to help anyone looking for the solution. Nevertheless without your answer to show it was true I probably wouldn't have looked hard enough. I'll keep trying to figure out the only other query here, which is why any panmagic $4\times4$ square is most-perfect. It's a known result but I haven't found a proof online, and I can't see intuitively why it's true. Alternatively, all I need for the purposes of this question is to show why any panmagic square satisfies $(1)$. Also thanks for pointing out my mistake; I used different numbering initially and forgot to change that. $\endgroup$
    – Anon
    Apr 18, 2020 at 6:42
  • $\begingroup$ Never mind, I've just realised why this is the case. I'm doing it in my head at work on mobile now, but I'll write it into the answer when I get back on my computer. Briefly, for each element $a$ there's a unique element $p(a)$ located 2 squares diagonally away from it. For each $a$ let $s(a)=a+p(a)$. Then you can prove there exist $x$ and $y$ with $x+y=34$ such that $s(a)=x$ for $a$ in row $0$ and $2$ and $s(a)=y$ for $a$ in row $1$ and $3$. Then rotate the argument to show that $s(a)=x$ for $a$ in column $0$ and column $2$ and $s(a)=y$ for $a$ in column $1,3$. Thus $x=y=17$ proving $(1)$. $\endgroup$
    – Anon
    Apr 18, 2020 at 7:13
  • 1
    $\begingroup$ @joriki Thanks again for helping with this! I've now edited it, showing why for $4\times4$ normal magic squares, the criteria that it satisfy $(1)$, that it satisfy $(2)$, that it be panmagic, and that it be most-perfect, are all equivalent. It was quite satisfying in the end to see why it all works out like that. In essence it's due to the high level of symmetry in these objects. $4\times4$ magic squares really are quite beautiful - you get a lot for what seems like a very little (requiring the $9$ subsquares to add to $34$). $\endgroup$
    – Anon
    Apr 18, 2020 at 12:01
  • 1
    $\begingroup$ If you'd only used a symbol to stand for the magic sum, rather than writing 34 explicitly, you'd have a proof that not only is every normal compact 4x4 magic square complete; every compact 4x4 magic square is complete. $\endgroup$
    – Rosie F
    May 8, 2020 at 13:54

Here’s Java code that finds all $4\times4$ squares filled with the numbers $1$ to $16$ in Frénicle standard form in which all four rows, all four columns, both diagonals, and all nine $2\times2$ subsquares sum to $34$. There are $48$ of them, so dropping condition $(1)$ does not yield any further squares.

  • $\begingroup$ +1 Thank you! I'll have to have more of a think to see why $(2)$ implies $(1)$ for $4\times4$ magic squares. $\endgroup$
    – Anon
    Apr 17, 2020 at 23:44
  • 1
    $\begingroup$ Thanks again for this answer. You prompted me to think about it more closely, and I think I understand why this is the case now. I've written up a separate answer to explain, but I'll keep yours the accepted answer. $\endgroup$
    – Anon
    Apr 18, 2020 at 4:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.