A magic square is a square matrix (N rows by N columns) with the following properties: 1. It contains the numbers 1 through N2, with each number appearing exactly once. 2. The sums of each row, each column, and both main diagonals are equal. For example, here is a "3 by 3" magic square: