Generate a fresh random maze in one click, pick its size and algorithm, then solve it right here with the arrow keys or print it for paper and pencil. Every maze has exactly one path from start to finish.
Difficulty
×
🏁
You solved it!
⏱ 0:00👣 0 moves
Tip: click the maze, then use the arrow keys or WASD. Hold Shift to run to the next junction. On phones, swipe on the maze.
Advertisement
Advertisement
How to use the Maze Generator
Pick a size with the Easy / Medium / Hard / Expert buttons or type your own width and height.
Choose an algorithm: the recursive backtracker makes long winding corridors, Prim's and Kruskal's make many short branches.
Press Generate maze to create a new random maze. The maze code lets you recreate the same maze later.
Play it: click the maze and use the arrow keys, WASD, swipes or the on-screen pad to walk from the green start to the orange finish. Hold Shift to run to the next junction.
Show the solution, or print / download PNG for a paper maze with an optional answer key.
How the maze algorithms work
Every maze starts as a grid where every cell has four walls. The generator then knocks down walls until all cells are connected. Because a wall is only removed when it joins two parts of the maze that were not yet connected, the result is a perfect maze: a spanning tree of the grid with no loops and exactly one route between any two cells.
Algorithm
How it works
What the maze looks like
Recursive backtracker
A randomized depth-first search. It walks to a random unvisited neighbour, removing the wall between, and backs up when it reaches a dead end.
Long, winding corridors and relatively few dead ends. Usually the hardest to solve by eye.
Prim's (randomized)
Keeps a list of cells next to the maze, picks one at random and connects it to a random cell that is already in the maze.
Many short dead ends branching off in all directions; a "bushy" texture.
Kruskal's (randomized)
Shuffles every wall and removes each one whose two cells are not yet connected, tracked with a union-find structure.
Evenly spread short passages, similar to Prim's but with less bias toward the starting point.
The solution shown with Show solution is found with a breadth-first search, which always finds the shortest route. In a perfect maze it is also the only route that does not double back.
Tips for solving and printing mazes
Wall follower: keep one hand on the same wall (left or right) and you will always reach the exit of a perfect maze whose start and finish are on the outer edge.
Work backwards: on paper, starting from the finish is often quicker because dead ends near the exit become obvious.
Dead-end filling: shade every dead end back to the nearest junction; whatever corridors remain unshaded form the solution.
Printing: square sizes up to about 40×40 fit a portrait page well. For wide mazes such as 50×36, choose landscape in the print dialog.
Classroom use: share the maze code so every student gets the identical maze, and print the answer key for yourself.
Frequently asked questions
Does every maze have a solution?
Yes. All three algorithms build a perfect maze: every cell is connected and there is exactly one path between any two cells, so there is always a single route from start to finish with no loops.
What is the difference between the algorithms?
The recursive backtracker (a randomized depth-first search) carves long, twisting corridors with fewer dead ends. Randomized Prim's and Kruskal's algorithms grow the maze from many places at once, which gives lots of short dead ends and a busier look. All produce perfect mazes.
How do I print a maze?
Press Print. The maze is placed on its own page with a title, and you can tick Include answer key to add a second page with the solution drawn in. You can also download a PNG and print it from any app.
What size maze is good for kids?
For young children 8×8 to 12×12 is a good start. Older kids usually enjoy 15×15 to 25×25, and adults can try 40×40 or larger. Bigger mazes print best on landscape paper.
Can I make the same maze again?
Yes. Each maze shows a maze code. Type that code into the Maze code box with the same size and algorithm and press Generate maze to get the identical maze.
How do I play on a phone?
Swipe on the maze in the direction you want to go, or use the arrow pad below it. Your trail is shown so you can see where you have been.