Magic Square Generator
Generate magic squares where all rows, columns, and diagonals sum to the same magic constant. This tool uses the Siamese method (De la Loubère's algorithm) for odd-sized squares.
All rows, columns, and diagonals sum to this number
Verification
What is a Magic Square?
A magic square is a square grid filled with distinct numbers (usually consecutive integers starting from 1) arranged so that the sum of numbers in each row, column, and diagonal is the same. This sum is called the magic constant.
Magic Constant Formula
For a magic square of order n (an n×n grid) using numbers from 1 to n²:
Magic Constant = n × (n² + 1) / 2
For example, a 3×3 magic square has a magic constant of 3 × (9 + 1) / 2 = 15.
The Siamese Method
This generator uses the Siamese method (also called De la Loubère's method), a simple algorithm for constructing magic squares of odd order:
- Start by placing 1 in the middle of the top row
- Move diagonally up and to the right to place the next number
- If this move goes outside the square, wrap around to the opposite side
- If the cell is already filled, move down one cell from the last number instead
- Repeat until all numbers are placed
History
Magic squares have fascinated mathematicians and mystics for thousands of years. They appear in:
- Ancient China - The Lo Shu Square (3×3) dates back to 650 BCE
- India - Used in astrological calculations and temple designs
- Islamic Mathematics - Extensively studied during the medieval period
- European Renaissance - Featured in Albrecht Dürer's engraving "Melencolia I" (1514)
Related Math Tools
Feedback
Help us improve this page by providing feedback, and include your name/email if you want us to reach back. Thank you in advance.
Sending...
Feedback sent. Thank you!
Error occurred!
-
-
-
-
-
-
-
- ABI Encoder / Decoder
- Block Estimator
- Calldata Cost
- CREATE2 Address
- ENS Availability
- ENS Cost Estimator
- ENS Lookup
- ENS Namehash
- ENS Record Viewer
- ENS Subname Explorer
- ERC-20 Unit Converter
- Gas Estimator
- HD Wallet Derivation
- Merkle Tree Visualizer
- 4-Byte Selector Lookup
- Solidity Storage Layout
- Transaction Decoder
- Vanity Address Estimator
- Wallet Address Validator
- Wei/Gwei/Ether Converter
-
-
-
-
-
- API Response
- ASCII Table
- Code Bug Detector
- Code Explanation
- CSS Beautifier
- Env Parser
- GraphQL Query
- Syntax Highlight
- HTML Beautifier
- JS Beautifier
- JSON Formatter
- JSONPath
- JWT Decoder
- JS keyCodes
- API Lorem Ipsum
- RegExp
- Regex Library
- Semver Compare
- SQL Beautifier
- TOML Formatter
- Code Unminifier
- XML Beautifier
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Amortization
- Break-Even
- Compound Interest
- Crypto Profit/Loss
- Debt Payoff
- Discount
- Effective Interest
- Emergency Fund
- Inflation Calculator
- Simple Interest
- Invoice Calculator
- IRR Calculator
- Mortgage
- NPV Calculator
- Portfolio
- Profit Margin
- Rent vs Buy
- Retirement Calc
- ROI Calculator
- Salary vs Hourly
- Savings Goal
- Tax Calculator
- VAT
-
-
-
-
-
-
-
-
-
-
-
-
- Equation Solver
- Exponent Calculator
- Factorial Calculator
- Fibonacci Sequence
- Fraction Calculator
- Fraction Simplifier
- GCD Calculator
- GCD/LCM
- Least Common Multiple (LCM) Calculator
- Logarithm Calculator
- Magic Square
- Matrix Calculator
- Number Base Converter
- Pascal's Triangle
- PDE Solver
- Prime Checker
- Prime Factorization
- Roman Numbers
- Scientific Notation
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Broken Link Checker
- Canonical URL Checker
- Core Web Vitals Checker
- Favicon
- Heading Structure
- Keyword Density
- Meta Tags
- Mobile-Friendly Test
- Open Graph Tags
- Page Load Time Analyzer
- Redirect Checker
- robots.txt
- Schema Markup
- SEO Optimized Checklist
- XML Sitemap
- Time on Page Tracker
- Page Title & Desc.
- Twitter Card Generator
-
-
-
-
-
-
- Acceleration
- Substance Amount
- Angle
- Area
- Astronomical
- Base Converter
- Capacitance
- Electric Charge
- Data Transfer
- Data Storage
- Density
- Energy Converter
- Force Converter
- Frequency Converter
- Fuel Economy
- Illuminance
- Inductance
- Length / Distance
- Power
- Pressure
- Electrical Resistance
- Time
- Speed
- Temperature
- Viscosity
- Volume
- Weight
-
-
-
-
-