This is a two-part answer. First, it establishes a non-trivial upper bound of 5. Then a solution is given that proves 5 is also the lower bound.
There is only one 3x3 magic square, up to symmetry:
294
753
618
So in order to have seven magic squares in a Sudoku, we require seven 5
s which aren't against an edge, and that requires two diagonally opposite corners to be 5
s. If we then look at parity (e
for even, o
for odd):
eoe
o5o
eoe
and consider the possible positions of the other 5
s, we eliminate almost all positions. E.g. consider the following grid:
5.. eoe ...
... o5o ...
... eoe ...
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... ... ..5
By Sudoku rules there are two possible places for the 5
in the top-right block, but the parity matching prohibits the 5
s from the magic squares being horizontally or vertically adjacent to an even number, so there's only one possible place:
5.. eoe ...
... o5o eoe
... eoe o5o
... ... eoe
... ... ...
... ... ...
... ... ...
... ... ...
... ... ..5
The 5
in the right-centre block is similarly forced; then the one in the centre block;
5.. eoe ... 5.. eoe ...
... o5o eoe ... o5o eoe
... eoe o5o ... eoe o5o
... ... eoe ..e oe. eoe
... ..e oe. ..o 5oe oe.
... ..o 5o. ..e oeo 5o.
... ..e oe. ... ..e oe.
... ... ... ... ... ...
... ... ..5 ... ... ..5
and we can't place any 5
in the left-centre block.
With the aid of a computer to check the 576 cases, this simple parity matching eliminates all but one of them:
5.e oe. ...
..o 5oe oe.
eoe oeo 5o.
o5o eoe oe.
eoe o5o eoe
.eo eoe o5o
.o5 oeo eoe
.eo eo5 o..
... .eo e.5
If we zoom in on the top-left 3 blocks:
5.e oe.
..o 5o.
eoE oe.
o5o
eoe
...
the two magic squares overlap on one even numbered cell, which I've labelled E
. Without loss of generality, let E = 2
. Then the numbers which are two cells up, down, left, and right of E
are suitably paired up 4
s and 6
s. But either we have two 4
s in the same row as E
, or we have two 4
s in the same column as E
, or we have two 4
s or two 6
s in the same block as E
. So the only grid which meets the parity constraints for seven magic squares fails as soon as we try to go beyond parity.
If we look for solutions with 6 magic squares we keep one 5
in a corner and allow the others to vary. There are 29 positions of 5
s which satisfy the parity check, and they all fail to the same kind of blockage between overlapping magic squares. So the upper bound for a solution is 5.
Solution with five magic squares (contributed by Geobits):
I found a template for this at http://www.sachsentext.de. Filling it in was a pain, but it's much easier once you realize that rotating/reflecting any of the magic squares causes it to break. Then you just have to fill in the "non-magic" spaces, which isn't much different than a regular sudoku board with a ton of givens.
(Peter resumes) Knuth's reduction of Sudoku to exact set cover can be augmented to add the magic square constraint. The reduction for standard Sudoku is to associate each $(\textrm{row}, \textrm{column}, \textrm{value})$ tuple with the set $\{\textrm{Row}(\textrm{row}, \textrm{value}), \textrm{Col}(\textrm{column}, \textrm{value}), \textrm{Block}(\lfloor\frac{\textrm{row}}3\rfloor, \lfloor\frac{\textrm{column}}3\rfloor, \textrm{value}), \textrm{Cell}(\textrm{row}, \textrm{column})\}$. Then an exact set cover of the union of all those sets provides exactly one instance of each value in each row, column, and block, and exactly one value per cell.
To extend for a magic square centred on $(r, c)$ we add a constraint for each of the four edges of the magic square that it must be one of the four sets $\{2,9,4\}, \{2,6,7\}, \{4,3,8\}, \{6,1,8\}$. This is sort-of related to the general lock puzzle: we can solve it with four "locks" and the following assignments:
2: A
4: B
6: C
8: D
1: AB
3: A C
7: B D
9: CD
This isn't quite strong enough to avoid false positives, but it narrows down the field considerably. With these extra constraints, and iterating over the possible positions of "internal" fives, I find 64 grids. Interestingly, some include "internal" fives which aren't from magic squares: e.g.
843 127 695
276 895 143
951 643 827
v
438 276 519
627 951 384
195 438 276
^
382 764 951
769 512 438
514 389 762
All of the ones I've checked have the same (IMO) structural defect that the magic squares are all in the same orientation. I haven't checked, but I think they may also all have a symmetry under rotation by 180 degrees and permutation of digits by $(19)(28)(37)(46)$.