About the Maze Generator
The Maze Generator draws a new random maze at whatever width and height you choose, from a quick 5x5 for preschoolers to a dense 40x40 for older kids and adults. The route runs from the top-left corner to the bottom-right corner, and you can show the solution on screen or print it on a second PDF page.
How it works
The tool starts with a grid where every cell has all four walls. It uses a randomized depth-first search, often called the recursive backtracker: beginning at the top-left cell, it moves to a random unvisited neighbor and knocks down the wall between them, then repeats. When it reaches a dead end with no unvisited neighbors, it backs up along its trail until it finds a cell that still has one. This continues until every cell has been visited.
The result is a perfect maze: every cell is reachable and there is exactly one path between any two cells, with no loops. That's why there is always one correct route. The solution is found with a breadth-first search from the top-left cell to the bottom-right cell, and it is drawn as a line through the centers of the cells along the way. Depth-first carving tends to produce long, winding corridors with relatively few short dead ends.
How to use
- 1
Enter the Width (cells) and Height (cells), each between 5 and 40; the size is kept in the page link.
- 2
Click New maze until you get a layout you like; the page link then reproduces that exact maze.
- 3
Click Show solution to check the route from top-left to bottom-right, and Hide solution to hide it again.
- 4
Click Download maze + solution as PDF to print the puzzle and its answer.
Worked examples
Preschool maze
A 4-year-old's first maze.
Classroom activity
A second-grade early-finisher sheet.
Landscape challenge
A wide maze for older kids.
Frequently asked questions
Is every generated maze guaranteed to be solvable?+
Yes. The generation algorithm visits every cell and carves a connected network with no loops, so there's always exactly one route from the start to the finish.
What's the largest maze size I can generate?+
Width and height are each capped at 40 cells, which keeps both the on-screen preview and the printed PDF readable.
Where are the start and finish?+
The route starts in the top-left cell and ends in the bottom-right cell. Click Show solution to see it. The outer wall has no gaps, so it helps to mark both corners on the printout.
Can I make a rectangular maze?+
Yes. Width and height are set separately, so you can make wide, tall, or square mazes anywhere from 5 to 40 cells per side.
What is a perfect maze?+
A maze with no loops and no isolated areas, where exactly one path connects any two points. All mazes from this tool are perfect mazes.