A magic square of order n is a square array of the numbers 1, 2, …, n² such that every row, column, or diagonal adds up to the same sum S.
Because nS = 1 + … + n², we have

S = n (n^{2}+1)/2 .

For instance, if n = 4, then S = 34.
A famous magic square of order four appears in Dürer's engraving *Melencolia*.
From studying this square, I developed a general theory of the algebraic structure hidden in it.
This structure depends on vector spaces over fields of prime order.
Behind every magic square of the kind to which it applies is an "affine map," so I refer to these as "affine magic squares."

The underlying mathematics of affine magic squares is not really difficult. A field of prime order is an arithmetical system with only finitely many numbers in it; the field of order 2, which is relevant to Dürer's square, has only the numbers 0 and 1. That could hardly be more simple. But it could be a lot more familiar; and to make these "prime fields" more familiar, I provide a prime field calculator.

The algebraic approach to Dürer's square begins by mapping the 4×4 square as a *vector space of dimension 4 over the field of order 2*.
This must sound even stranger, to the non-mathematician.
Therefore I provide an interactive page about Finite Vector Spaces which I hope will make it easier to think about such a square as a vector space, with interesting subspaces.
The numbers in the square are also mapped, in a different way, as a finite vector space; one of the applets on that page shows how this identification works.

The positions in the square, and the numbers filling those positions, are both mapped to a finite vector space. The assignment of numbers to positions is a map of the vector space onto itself. For affine magic squares, this is (unsurprisingly) an affine map. The magic properties of the square imply certain restrictions on this map; the page Affine Magic Squares explains how this works, and has an applet with which you can construct affine magic squares of several sizes.

Any interesting mathematical theory calls out for extension and generalization. The Extensions page provides some.

When I first worked out the concept of affine magic squares, I wondered if it was really new. In a way, it isn't. Not only the Dürer square, but many other published examples, are in fact affine. The simplest affine squares, where the order is an odd prime, are special cases of a technique for constructing squares of odd order; in various forms, this technique has been known for a long time. Some authors describe methods of constructing magic squares that are special cases of the technique of affine magic squares. I regard these examples as independent discoveries. In particular, Allan Adler has given a very general definition of affine magic squares, cubes. etc.

Once affine magic squares are defined, it is a challenge counting them. I found this an interesting and solvable problem. The solution is necessarily more technical than the rest of this web site.