Clever Quest Lab Tools

Maze Generator

Make perfect mazes for worksheets and puzzle pages, rectangular or circular, and pick one of six algorithms by the challenge you want: one long winding path or many short dead ends. A seed rebuilds the same maze, and a printout can include an answer key.

Your maze

Start Finish

Solution
—
Dead ends
—
Cells
—
Passages
—

Settings

Shape
Size
Any word or number. The same seed and settings always give the same maze.

Cell size sets the pixel size of the SVG and PNG files; the preview and the printout scale the maze to fit.

Print and download

Mazes per page

The worksheet never shows the solution. SVG and PNG files match the preview, with the solution line if it is switched on.

—

Everything runs in your browser. Your settings are saved on this device only, and nothing is uploaded.

Runs on your device. Nothing you type or record is uploaded. Keeps working without a connection while the page is open. Works with touch. Saves your settings and seed on this device, so a reload brings back the same maze.

Added

How to use the maze generator

  1. Pick a shape (rectangular or circular) and a size: Easy, Medium, Hard, or type your own rows and columns (2 to 100) or rings (2 to 40).
  2. Choose an algorithm; the note under it describes the look.
  3. Choose where the entrance and exit go. The openings are cut into the outer wall and marked with a circle (start) and a square (finish).
  4. Press New maze for a fresh random seed, or type a seed of your own to get a maze back later.
  5. Press Show solution to draw the shortest path, and read the solution length and the number of dead ends under the maze.
  6. Under Print and download, choose 1, 2 or 4 mazes per page and whether to add an answer key, then print, or save the maze as an SVG or PNG file.

How it works

Every maze here is a perfect maze: each cell can be reached, and there is exactly one route between any two cells, so there are no loops. Treat the cells as points and every opening between two neighbouring cells as a line joining them, and a perfect maze is a spanning tree of the grid. A tree that joins n cells always has exactly n − 1 passages, which is why a 20 × 20 maze shows 400 cells and 399 passages.

The solution comes from a breadth-first search (BFS). Starting at the entrance, it visits cells in order of distance and remembers where it came from; when it reaches the exit, following those notes backwards gives the shortest path. A dead end is a cell with a single opening, not counting the start and finish cells.

The seed text is turned into a 32-bit number that starts a pseudorandom number generator. The same seed with the same shape, size, algorithm and entrance setting always gives the same maze, in any browser. Cell size, wall thickness, markers and the solution line only change the drawing.

A circular maze has a centre cell and rings around it. Ring i gets the previous ring's cell count multiplied by round(2π × i ÷ previous count), which keeps the cells roughly square: 6, 12, 24, 24, 24, 48 cells and so on. Ten rings make 331 cells.

"Farthest apart" runs two searches: from any edge cell to the farthest edge cell, then from that cell to the edge cell farthest from it. In a tree, that pair has the longest route of all edge cells.

Examples

Example 1 — the default maze. Rectangular 20 × 20, recursive backtracker, top-left to bottom-right, seed 2026: the solution runs through 167 of the 400 cells, and there are 39 dead ends (10%).

Example 2 — same seed, Kruskal's. Change only the algorithm: the solution drops to 59 cells and the dead ends rise to 120 (30%).

Example 3 — binary tree. With the corner entrances the solution is 39 cells, the shortest route that is possible on a 20 × 20 grid, and it is 39 for every seed: along the open top row, then down the open right column. Switch to "Farthest apart along the edge" and the same maze gives a 73-cell solution.

Example 4 — circular. 10 rings, Wilson's, centre to the outside, seed 2026: 331 cells, 330 passages, a solution of 76 cells and 90 dead ends (27%).

Which algorithm makes the hardest maze?

There are two kinds of difficulty. A long, winding solution takes time to trace; many dead ends offer many wrong turns. The table shows averages over 10,000 random 20 × 20 mazes with corner entrances (seeds x1 to x10000), measured with this page's code on 22 October 2026. The shortest possible solution on this grid is 39 cells.

AlgorithmDead endsAverage solution
Recursive backtracker10% of cells117 cells
Randomized Prim's32%44 cells
Randomized Kruskal's30%58 cells
Wilson's29%60 cells
Binary tree25%39 cells
Eller's28%57 cells

The backtracker varies the most: eight in ten of its solutions are between 73 and 171 cells.

For a long trail, use the backtracker; for many short wrong turns, Prim's or Kruskal's on a larger grid.

Printing tips

Frequently asked questions

How do I make the same maze again?

Note the seed and the settings: together they always rebuild the same maze. The page also remembers your last settings on this device.

What is the difference between SVG and PNG?

SVG is a vector file: it stays sharp at any size and opens in vector drawing programs. PNG is an image at twice the cell size, for example 1020 × 1020 pixels for the default maze (at most 8,000 pixels a side for very large mazes). Both have a white background.

Why is the binary tree maze so easy from corner to corner?

Every cell opens north or east, so the whole top row and the whole right column are straight corridors that join the two corners.

Can it solve mazes step by step?

This page shows the finished shortest path only. To watch breadth-first search, A* and other searches explore a grid one cell at a time, use the Pathfinding Visualizer.

Sources