How to Solve a Maze: Five Methods for Maze Puzzles

This article was written with AI and may contain mistakes. Found one? Tell us.

By Riddle10 Editorial Published 11 min read

To solve a maze, choose the method that fits it: keep one hand on a wall in a simple walk-through maze, shade in the dead ends when the whole maze is printed in front of you, and mark every junction you pass when you cannot see the layout. If those stall, work backwards from the goal, or search each branch in a fixed order, the way a computer does.

This guide explains all five methods, shows where each one breaks down, and then solves a single maze with four of them so you can compare. A practice maze with its answer comes at the end.

Which maze solving methods are there?

Each method suits a different situation. The biggest question is whether you can see the whole maze at once, as on a printed page, or only the corridor around you, as in a hedge garden.

MethodBest used whenNeeds the whole maze in view?Can it let you down?
Hand on one wallWalking a maze with no loopsNoYes, with loops or a goal in the middle
Dead-end fillingSolving a printed mazeYesNo, but it is slow on very large mazes
Marking junctionsWalking any maze from insideNoNo, if you follow the rules strictly
Working backwardsThe goal sits at the end of a long corridorYesNo, but it only helps when the goal end is simpler
Searching every branch in orderComputers, or very patient solversNoNo, it always ends

You can mix them. A good plan is to shade a few obvious dead ends first, then trace backwards from the goal, and only fall back on a full search if the middle of the maze is still a tangle.

How does the hand-on-wall method work?

Put one hand on a wall at the entrance, either the left or the right, and walk forward without ever lifting it. At every junction your hand drags you into the first opening on that side. At a dead end you simply follow the wall round and come back out.

The idea is that the walls you touch form one long unbroken surface. If the entrance and the goal both sit on that surface, following it must bring you to the goal sooner or later.

The method needs no memory at all, which is its great strength. Its weakness is speed. Your hand pulls you into every side branch on its side of the maze, so you often walk most of the corridors before you arrive. Which hand you choose can make a large difference, as the worked example below shows.

When does keeping a hand on the wall fail?

It fails whenever the wall you are touching does not connect to the goal. That happens in two common ways.

Loops. Some mazes contain a block of walls that stands on its own, with corridors running all the way round it. If you start with your hand on that block, you circle it forever and never reach anything new.

A goal in the middle. Some garden mazes put the goal in the centre, surrounded by rings of corridor. If the walls around the centre are not joined to the outer wall, a hand on the outer wall carries you all the way round the outside and back to the entrance without ever reaching the middle.

A quick test helps with a printed maze: trace the wall you plan to follow with a pencil. If it reaches the wall beside the goal, the method will work. If it closes into a ring that never touches the goal, pick another method.

How does dead-end filling work?

Dead-end filling is the best method when the whole maze lies in front of you. Find every dead end, meaning a cell with walls on three sides, and shade it in. Then keep shading backwards along that corridor until you reach a junction.

When you shade a branch away, the junction it came from loses an exit. If that junction now has only two openings left, it has turned into a plain corridor, and the dead end you were filling carries on through it. Keep going until no unshaded dead ends remain.

What is left is the solution. In a maze with no loops, only the route from start to goal survives the shading. In a maze with loops, the loops survive too, and you pick the shortest way round them by eye.

Treat the start and the goal as if they were open doors, never as dead ends, or you will shade the answer away.

How do you mark junctions so you never get lost?

When you are inside a maze and cannot see its layout, marking is the method to trust. You leave a small sign at the mouth of every corridor you use, such as a chalk line or a pebble, and you follow six rules.

  1. Mark each corridor mouth as you enter it and as you leave it. A corridor you have walked once has one mark at each end; a corridor you have walked twice has two.
  2. At a junction you have never visited, take any corridor with no marks.
  3. If you reach a junction you have visited before, and the corridor you just walked had no marks when you entered it, turn round and go back the way you came. This stops you running round a loop.
  4. If you reach a junction by walking a corridor for the second time, such as on your way back from a dead end, take a corridor with no marks if there is one; if not, take one with a single mark.
  5. At a dead end, turn round and walk back to the junction you came from.
  6. Never enter a corridor that already has two marks. It is used up.

Followed in full, these rules mean no corridor is ever walked more than once in each direction, so the walk always ends. You either reach the goal or return to the entrance knowing that no route exists. On the way out, follow the corridors with one mark, and they lead you straight back.

Why does working backwards from the goal help?

The two ends of a maze are not always equally hard. In some mazes the start end holds most of the branching while the goal end is plainer, and then starting at the goal and tracing towards the entrance skips many of the traps.

With a printed maze, put your pencil on the goal and follow the corridor away from it. Count how many choices you meet. If the goal end of the maze has fewer junctions than the start end, the backwards route is the faster one. When you meet a junction, check each branch for a quick dead end before you commit.

The same trick helps with any puzzle that has one fixed ending and many possible beginnings. Asking where you must have come from is often easier than asking where you could go next.

How does a computer search every branch?

A computer has no hand to put on a wall, so it uses a fixed search. A simple one follows one branch as far as it can and backs up only when it is stuck.

This method is called depth-first search, and a paper published on 18 June 2021 applies it to networks of dots joined by one-way lines [2]. In that paper the search ends when no point is left unvisited; until then it keeps moving on to a neighbour it has not seen, and whenever it has none it retreats to the latest point that still offers an unseen neighbour, beginning from one chosen root point [2].

In this guide's comparison, that is junction marking done by machine. The visited list plays the part of your chalk marks, and backing up to the last unfinished junction is the same as returning along a corridor you have already used.

The same paper also runs the search backwards from a target point, following each line against its direction, and when several lines are possible it takes the heaviest one first [2]. In the networks it studies, every point has a way through to the target, so this backward search reaches all of them [2].

That backward search was used on networks, not mazes. The lesson drawn here for maze solvers is this guide's own: a careful search can begin at either end, and choosing the end with fewer branches saves work.

How do maze robots find their way?

Robots that drive through real mazes add a step that a pencil never needs: sensing where the corridors are. A paper published on 7 December 2021 tested a small two-wheeled robot that steered along a black guide line through a maze, with a neural network trained by back-propagation choosing its movements [1].

The paper names odometry as the most common way for such robots to navigate: the robot keeps a running estimate of where it is and builds a plan of the ground it has covered [1]. Once that plan exists, it adds, the car can follow its guide line at high speed [1].

Its authors judged that the same network would also steer the robot round circular or oval tracks, not only through a maze [1]. The link to hand solving is simple: a robot that remembers where it has been is doing the same job as your junction marks.

How do the methods compare on one maze?

Here is an original grid maze to try. A filled square is a wall and a dot is an open cell. Each step takes you to the next open cell above, below, left or right, never diagonally. The start is on the left edge in row four and the goal is on the right edge, level with it.

ABCDEFGHI
row one····■···■
row two·■■■··■··
row three·····■·■·
row fourStart■■·■··■Goal
row five·■··■·■·■
row six··■■■·■··
row seven■·······■

Try it yourself first. Then follow the steps below, which use each method in turn.

Step one: find the dead ends and junctions. The maze has forty-one open cells. Five of them are dead ends: row one column D, row three column G, row five column C, row five column H and row six column I. Four cells are junctions, where you have a real choice: row three column A, row three column D, row six column H and row seven column F.

Step two: fill the dead ends. Shade from each dead end back to its junction. The branch ending at row five column C ends quickly.

The dead ends at row five column H, row six column I and row three column G drain away the junctions at row six column H and row seven column F, so the whole lower half becomes one long dead end that runs back along the bottom row and up the left side to the start. The top-left strip is shaded out too.

In all, twenty-six cells are shaded and fifteen remain, and those fifteen cells form the only route.

Step three: work backwards. Put your pencil on the goal. The corridor climbs up from the goal, crosses the top right and drops back down to row three, and it meets no junction at all for ten moves, until it reaches row three column D. There one branch drops down into the short dead end at row five column C, so the other branch, leading left along row three, must be the way.

Working backwards solves this maze with a single easy choice.

Step four: try both hands. Enter facing right. With your left hand on the wall you first wander up into the top-left strip and back, then follow row three to the goal: twenty-four moves in all.

With your right hand you are pulled down the left side and round the whole lower half before you come back up, and you need fifty-six moves. Both hands arrive, because this maze has no loops, but one hand takes more than twice as long as the other.

The route. From the start, go up one cell to row three, right four cells to column E, up one cell, right one cell to column F, up one cell to row one, right two cells to column H, down one cell, right one cell to column I, and down two cells to the goal.

That is fourteen moves, and a computer check of every possible path confirms it is the only route from start to goal that never visits a cell twice.

Method on this mazeMoves walked or resultVerdict
Dead-end fillingLeaves only the fourteen-move routeClean and certain
Working backwardsOne choice, at row three column DFastest by hand
Left hand on the wallTwenty-four movesFine
Right hand on the wallFifty-six movesArrives, but very slowly

Can you solve this practice maze?

This smaller maze uses the same rules. Start at the top left and reach the goal at the bottom right. Try working backwards from the goal, or fill the dead ends first.

ABCDEFG
row oneStart····■·
row two·■■■···
row three·■··■·■
row four···■···
row five■·■··■Goal

Answer: From the start, go right four cells along row one to column E, then step down into row two, take one step right into column F, drop two cells to row four, take one more step right into column G, and finish with a single step down onto the goal. That is ten moves.

The maze has four dead ends, at row one column G, row three column D, row five column B and row five column D, and filling them leaves only that route. A computer check of every path confirms there is exactly one route that never repeats a cell. A left-hand walk entering to the right reaches the goal in fourteen moves, while a right-hand walk needs thirty-two.

What maze should you try next?

Now that you can fill dead ends, mark junctions and work backwards, try a garden maze where you must pick the one gate that leads to the fountain. Try working from the fountain end if that helps.

References

  1. Horváth, D., & Červeňanská, Z. (2021, December 7). Controlling a Small Mobile 3-Pi Robot Movement in a Maze via the Neural Network Using Back-Propagation Learning Method. Research Papers Faculty of Materials Science and Technology Slovak University of Technology, 29(49), 43-50. DOI 10.2478/rput-2021-0023
  2. Knierim, C., Larcher, M., & Martinsson, A. (2021, June 18). Note on Long Paths in Eulerian Digraphs. The Electronic Journal of Combinatorics, 28(2), P2.37. DOI 10.37236/10297

maze puzzles how to solve wall follower dead end filling path puzzles step by step

More reading