Maze Generator
Printable mazes in four sizes, every one a perfect maze — exactly one path between any two points, with no loops and no unreachable areas.
A perfect maze
Every cell is reachable, there are no loops, and there is exactly one path between any two points. That makes the solution unique and guarantees there are no closed-off pockets — which is not true of a maze drawn by hand or generated carelessly.
There is a tidy consequence: a perfect maze on N cells has exactly N − 1 passages, because it is a spanning tree. Count the passages and you have proved the maze is correct without ever walking it — which is precisely how this one is tested, and how the maze above is checked the moment it is drawn:
Things worth knowing
- This is a perfect maze: every cell is reachable, there are no loops, and there is exactly one path between any two points. That means the solution is unique and there are no closed-off pockets.
- A perfect maze on N cells always has exactly N−1 passages, because it is a spanning tree. Count them and you have proved the maze is correct without walking it.
- The generator is a recursive backtracker, which produces long winding corridors and relatively few junctions. Other algorithms give a very different feel — Prim’s makes short bushy dead ends, and Kruskal’s looks more uniform.
- The hardest mazes for a person are not the largest, they are the ones with the most junctions near the start. A long corridor is nothing to solve however far it runs.
- Following one wall with your hand solves any perfect maze, eventually. It fails only on mazes with loops — which is exactly what "perfect" rules out.
How to use
- Choose a size and generate a maze.
- Print it, or solve on screen.
- Use the solution view if you get stuck.
- Try wall-following as a strategy on a perfect maze.
Frequently asked questions
What is a perfect maze?
One where exactly one path connects any two points — no loops, no isolated sections, no shortcuts. Mathematically it is a spanning tree of the grid, which is a tidy way of saying every cell is reachable and there is never more than one way to get there.
Does the wall-following trick always work?
On a perfect maze with the entrance and exit on the outer wall, yes — keeping one hand on the same wall throughout will eventually reach the exit, though possibly the long way round. It fails on mazes with loops, where you can circle an island forever.
How are mazes generated?
By carving passages through a grid using a spanning-tree algorithm — depth-first search with backtracking, or Prim's or Kruskal's algorithm. Each produces a different character: depth-first gives long winding corridors, while Prim's produces shorter branches and more frequent junctions.
Which algorithm makes the hardest mazes?
Depth-first search generally feels hardest to a human solver, because its long corridors with few branches mean a wrong turn costs a great deal of backtracking. Mazes with many short branches look more intimidating and are usually quicker to solve.
What is the best way to solve one by hand?
Working backwards from the exit is often easier, since dead ends tend to be designed to trap forward progress. Filling in dead ends as you find them — a technique sometimes called dead-end filling — reduces the maze to its solution path and works reliably on paper.
Are there mazes without a solution?
A perfect maze always has one by construction. Mazes with unreachable regions are possible but are generally considered defective rather than difficult, which is why generators check connectivity — a puzzle that cannot be solved is not a hard puzzle.
🔒 This tool runs entirely in your browser. Nothing you enter is uploaded, logged, or stored.