Maze Generator
Generate printable random mazes with your own size, algorithm and seed — drawn in your browser and downloadable as SVG or PNG.
- Grid
- —
- Cells
- —
- Passages carved
- —
- Solution length
- —
- Dead ends
- —
The maze starts at the gap in the top-left corner and finishes at the gap in the bottom-right corner. Every maze here is a perfect maze: no loops, no closed rooms and exactly one route between any two squares.
How it works
This maze generator builds a grid of square cells and then knocks down walls until every cell is reachable. You can pick between three classic algorithms. Recursive backtracker (a randomized depth-first search) walks as far as it can before backing up, which produces long, winding corridors and few dead ends — the hardest of the three. Randomized Prim's algorithm grows the maze outward from one cell by picking a random wall on the frontier each time, giving a bushier maze with many short branches. Binary tree gives every cell a passage either north or west; it is fast and easy but has an obvious diagonal bias and a straight corridor along the top row and left column.
All three produce a perfect maze — a spanning tree of the grid. That is why the
passage count is always exactly cells − 1 (a 20 × 20 maze has 400 cells and 399
passages) and why there is exactly one path between the entrance and the exit. That path is
found with a breadth-first search from the top-left cell to the bottom-right cell, and the
solution length is counted in cells including both ends.
The seed makes results repeatable: the same seed, size and algorithm always draw the same
maze, so you can share a seed with someone and you will both solve the identical puzzle.
Download it as a crisp .svg for printing at any size, or as a .png
for slides and worksheets. Everything is generated in your browser with plain JavaScript —
nothing is uploaded, there is no sign-up and there are no ads.
Frequently asked questions
How does a maze generator work?
It starts with a full grid of walled-off square cells and knocks down walls until every cell is reachable, which makes the maze a spanning tree of the grid — a 'perfect maze' with no loops, no closed-off rooms and exactly one route between any two squares. That is why the passage count is always exactly cells − 1: a 20 × 20 maze has 400 cells and 399 passages. This page offers three classic methods. The recursive backtracker is a randomized depth-first search that walks as far as it can before backing up, producing long winding corridors and few dead ends. Randomized Prim's algorithm grows outward from one cell by picking a uniformly random wall on the frontier, giving a bushier maze with many short branches. The binary tree algorithm gives every cell a passage either north or west — fast and easy, but with a visible diagonal bias and straight corridors along the top row and left column. The solution shown is found with a breadth-first search from the entrance to the exit.
Can I print the maze or reuse the same one later?
Yes. Download it as an .svg and it prints razor-sharp at any paper size, because vector output has no fixed resolution — ideal for classroom worksheets and activity books. The .png export is rendered at 2× for slides and documents. To get the identical maze back another day, note the seed, the column and row counts and the algorithm: the generator is fully deterministic, so those four settings always redraw exactly the same maze. 'Copy share text' puts all of them on your clipboard along with the solution length, so you and a friend can race the same puzzle.
What size maze should I use, and how do I make it harder or easier?
For young children try roughly 10 × 10 with the binary tree algorithm — its solution is always a straight staircase of cols + rows − 1 cells, so it is forgiving. For a normal puzzle 20 × 20 with the recursive backtracker is a good default; its long corridors and low dead-end count make wrong turns expensive. For a real challenge go up towards 50 × 50 with the recursive backtracker, where the solution can wind through hundreds of cells. Randomized Prim's sits in between: lots of short dead ends make it feel busy but the true route is often fairly direct. Watch the 'Solution length' and 'Dead ends' figures as you change settings — they are the quickest measure of how tough the maze really is.