← All tools Generator

Maze Generator

Generate random mazes with adjustable dimensions, reveal the solution path, and export your creation as SVG or PNG — all in your browser.

15
15
Click "Generate" to create a maze
StartEnd15 × 15225 cells

How Maze Generation Works

This tool uses the recursive backtracking algorithm, one of the most popular approaches for generating perfect mazes. A perfect maze is one where every cell is connected to every other cell by exactly one path — there are no loops and no isolated sections. The algorithm begins at a starting cell, marks it as visited, then repeatedly picks a random unvisited neighboring cell, removes the wall between them, and moves into the new cell.

When the algorithm reaches a cell with no unvisited neighbors, it backtracks along its path until it finds a cell with at least one unvisited neighbor, then continues carving. This depth-first approach tends to create mazes with long, winding corridors and relatively few short dead ends, making them visually appealing and moderately challenging to solve.

Choosing the Right Grid Size

The grid size you choose affects both difficulty and visual density. Smaller mazes (10x10 to 15x15) are ideal for young children, quick warm-up puzzles, or embedding as decorative elements. Medium mazes (20x20 to 30x30) strike a balance between challenge and solvability — they work well for printed puzzle sheets and classroom activities.

Large mazes (35x35 to 50x50) are genuinely difficult and can take several minutes to solve by hand. They are popular for competitive puzzle events, stress-testing pathfinding algorithms, or creating poster-sized prints. Keep in mind that doubling the linear dimension quadruples the total cell count, so a 50x50 maze has 2,500 cells compared to just 100 in a 10x10.

Exporting and Using Your Maze

The generator supports two export formats. SVG (Scalable Vector Graphics) produces a resolution-independent file that can be scaled to any size without losing quality — perfect for printing on large paper or embedding in design tools like Figma or Illustrator. PNG (Portable Network Graphics) creates a pixel-based image at a fixed resolution, which is convenient for sharing on social media, inserting into slideshows, or uploading to websites.

Both formats include the start marker (green dot at the top-left), the end marker (red dot at the bottom-right), and optionally the solution path if you have it toggled on. This makes it easy to create answer keys for printed maze worksheets.

Other Maze Algorithms

While recursive backtracking is the algorithm used here, many other approaches exist. Kruskal's algorithm treats every cell as a separate set and randomly merges adjacent sets by removing walls, producing mazes with a more uniform distribution of corridor lengths. Prim's algorithm grows the maze from a frontier of cells adjacent to the visited region, creating mazes that tend to branch more evenly from the starting point.

Binary tree and sidewinder algorithms are simpler and faster but produce mazes with noticeable directional bias. Eller's algorithm can generate mazes one row at a time with constant memory, making it suitable for infinitely long mazes. Each algorithm produces mazes with distinct visual textures and solving characteristics, making the study of maze generation a rich area within recreational mathematics and computer science.

Frequently Asked Questions

What is recursive backtracking in maze generation?

Recursive backtracking is a depth-first search algorithm that carves passages through a grid by randomly choosing an unvisited neighbor, removing the wall between the current cell and that neighbor, then repeating. When it hits a dead end, it backtracks to the last cell with unvisited neighbors and continues. This produces mazes with long, winding corridors and exactly one solution.

How do I export a generated maze as an image?

Click the "Export SVG" button for a scalable vector file that stays sharp at any size, or "Export PNG" for a standard raster image. Both formats include start/end markers and the solution path if you have it toggled on.

What grid sizes are supported?

You can generate mazes from 10x10 up to 50x50 cells using the row and column sliders. Smaller grids produce quick, easy puzzles while larger grids create genuinely challenging mazes with thousands of cells.

Is there always a solution to the generated maze?

Yes. The recursive backtracking algorithm guarantees that every cell is reachable from every other cell, so there is always exactly one unique path between start and end. Toggle the solution to see it highlighted in cyan.

Can I use generated mazes for commercial projects?

Yes. Mazes are generated randomly in your browser with no server involvement. You are free to export and use them in printed puzzle books, educational materials, games, or any other project without attribution.

Related Tools