Maze Generator

Generate printable mazes with a guaranteed solution path.

Open tool

Overview

The Maze Generator produces printable rectangular mazes with a guaranteed single solution path from a marked start to a marked end. Pick width, height, and difficulty (which controls dead-end density), then export the result as a printable image for puzzle books, classroom worksheets, or game-prep handouts.

The output is always a "perfect" maze — every cell is reachable, every pair of cells has exactly one path between them, and there are no loops or isolated regions. That makes solutions unambiguous and ensures the puzzle has a real "aha" moment without trial-and-error backtracking.

How it works

The generator runs a randomised depth-first search on a grid graph where every cell starts walled off from its neighbours. Starting from a random cell, the algorithm picks a random unvisited neighbour, carves the wall between them, and recurses; when no unvisited neighbour exists, it backtracks. The result is a uniform spanning tree of the grid — a connected acyclic subgraph that visits every cell.

Because the maze is a tree, there's exactly one simple path between any two cells, which is the unique solution. Difficulty is controlled by post-processing: lower-difficulty mazes can add a few extra openings to create shortcut shortcuts (sacrificing perfectness but reducing solve time), and higher-difficulty mazes keep the strict tree structure for maximum dead-end branching.

Examples

  • A 20x20 maze typically contains 400 cells, 399 wall removals, and dozens of dead ends.
  • A 5x5 maze is solvable in well under a minute and is suitable for young children.
  • Setting width and height equal produces a square maze; rectangular dimensions work equally well.
  • Printing at 50 cells per page width produces a challenging full-page puzzle for adults.

FAQ

Is every generated maze solvable?
Yes. The generator always produces a connected tree of cells with one path from start to end.

Where are the start and end?
By default the start is the top-left cell and the end is the bottom-right; both are clearly marked on the printed maze.

Can I generate non-rectangular mazes?
Only rectangular grids are supported. Hex and triangular grids would need a different algorithm.

How large can the maze be?
Hundreds of cells per side work fine. Multi-thousand-cell mazes start to slow generation and print awkwardly.

Does the same dimensions always produce the same maze?
No — each generation samples a fresh spanning tree. Re-running the tool gives a different maze each time.

Try Maze Generator

An unhandled error has occurred. Reload ×