Magic Square

A Magic Square is a table of integers whose rows, columns and diagonals all add up to the same number. Here is how you can make one:

  1. Choose the size, n ´ n. n must be an odd number.
  2. Start at 1, and fill up the square by counting from 1 up to n ´ n, left to right, top to bottom.
  3. Leave the middle column alone.
  4. Starting with the column to the left of centre, shift the numbers down one row. The bottom number comes up to the top.
  5. The next column to the left gets shifted down by 2 rows. The bottom two numbers come up to the top.
  6. Continue shifting columns down one extra each time until you reach the first column.
  7. Starting with the first column to the right of centre, shift the numbers UP one row.
  8. The next column to the right of centre gets shifted up by 2, and so on until you reach the far right column.
  9. Repeat the same procedure, only this time with the rows: Start with the row above centre, and shift right one column.
  10. The row above that, shift right by 2 columns. Continue until the top.
  11. Finally, repeat for rows below centre, only shifting left instead of right.

 

Each row, column, and diagonal will add up to n(n2+1)/2.

Here is a 31 ´ 31 magic square.

498

531

564

597

630

663

696

729

762

795

828

861

894

927

960

1

34

67

100

133

166

199

232

265

298

331

364

397

430

463

496

530

563

596

629

662

695

728

761

794

827

860

893

926

959

31

33

66

99

132

165

198

231

264

297

330

363

396

429

462

495

497

562

595

628

661

694

727

760

793

826

859

892

925

958

30

32

65

98

131

164

197

230

263

296

329

362

395

428

461

494

527

529

594

627

660

693

726

759

792

825

858

891

924

957

29

62

64

97

130

163

196

229

262

295

328

361

394

427

460

493

526

528

561

626

659

692

725

758

791

824

857

890

923

956

28

61

63

96

129

162

195

228

261

294

327

360

393

426

459

492

525

558

560

593

658

691

724

757

790

823

856

889

922

955

27

60

93

95

128

161

194

227

260

293

326

359

392

425

458

491

524

557

559

592

625

690

723

756

789

822

855

888

921

954

26

59

92

94

127

160

193

226

259

292

325

358

391

424

457

490

523

556

589

591

624

657

722

755

788

821

854

887

920

953

25

58

91

124

126

159

192

225

258

291

324

357

390

423

456

489

522

555

588

590

623

656

689

754

787

820

853

886

919

952

24

57

90

123

125

158

191

224

257

290

323

356

389

422

455

488

521

554

587

620

622

655

688

721

786

819

852

885

918

951

23

56

89

122

155

157

190

223

256

289

322

355

388

421

454

487

520

553

586

619

621

654

687

720

753

818

851

884

917

950

22

55

88

121

154

156

189

222

255

288

321

354

387

420

453

486

519

552

585

618

651

653

686

719

752

785

850

883

916

949

21

54

87

120

153

186

188

221

254

287

320

353

386

419

452

485

518

551

584

617

650

652

685

718

751

784

817

882

915

948

20

53

86

119

152

185

187

220

253

286

319

352

385

418

451

484

517

550

583

616

649

682

684

717

750

783

816

849

914

947

19

52

85

118

151

184

217

219

252

285

318

351

384

417

450

483

516

549

582

615

648

681

683

716

749

782

815

848

881

946

18

51

84

117

150

183

216

218

251

284

317

350

383

416

449

482

515

548

581

614

647

680

713

715

748

781

814

847

880

913

17

50

83

116

149

182

215

248

250

283

316

349

382

415

448

481

514

547

580

613

646

679

712

714

747

780

813

846

879

912

945

49

82

115

148

181

214

247

249

282

315

348

381

414

447

480

513

546

579

612

645

678

711

744

746

779

812

845

878

911

944

16

81

114

147

180

213

246

279

281

314

347

380

413

446

479

512

545

578

611

644

677

710

743

745

778

811

844

877

910

943

15

48

113

146

179

212

245

278

280

313

346

379

412

445

478

511

544

577

610

643

676

709

742

775

777

810

843

876

909

942

14

47

80

145

178

211

244

277

310

312

345

378

411

444

477

510

543

576

609

642

675

708

741

774

776

809

842

875

908

941

13

46

79

112

177

210

243

276

309

311

344

377

410

443

476

509

542

575

608

641

674

707

740

773

806

808

841

874

907

940

12

45

78

111

144

209

242

275

308

341

343

376

409

442

475

508

541

574

607

640

673

706

739

772

805

807

840

873

906

939

11

44

77

110

143

176

241

274

307

340

342

375

408

441

474

507

540

573

606

639

672

705

738

771

804

837

839

872

905

938

10

43

76

109

142

175

208

273

306

339

372

374

407

440

473

506

539

572

605

638

671

704

737

770

803

836

838

871

904

937

9

42

75

108

141

174

207

240

305

338

371

373

406

439

472

505

538

571

604

637

670

703

736

769

802

835

868

870

903

936

8

41

74

107

140

173

206

239

272

337

370

403

405

438

471

504

537

570

603

636

669

702

735

768

801

834

867

869

902

935

7

40

73

106

139

172

205

238

271

304

369

402

404

437

470

503

536

569

602

635

668

701

734

767

800

833

866

899

901

934

6

39

72

105

138

171

204

237

270

303

336

401

434

436

469

502

535

568

601

634

667

700

733

766

799

832

865

898

900

933

5

38

71

104

137

170

203

236

269

302

335

368

433

435

468

501

534

567

600

633

666

699

732

765

798

831

864

897

930

932

4

37

70

103

136

169

202

235

268

301

334

367

400

465

467

500

533

566

599

632

665

698

731

764

797

830

863

896

929

931

3

36

69

102

135

168

201

234

267

300

333

366

399

432

466

499

532

565

598

631

664

697

730

763

796

829

862

895

928

961

2

35

68

101

134

167

200

233

266

299

332

365

398

431

464


Last Updated on 2001-08-17
By Owen Lawrence