Locker Puzzle: Which 10 Lockers Stay Open?

The locker puzzle is a classic math brain teaser where 100 students each toggle the lockers in a 100-locker hallway, and in the end, only the perfect square lockers, numbers 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100, stay open. It is a story of pattern and patience, a puzzle that feels like a prank at first but reveals a beautiful rule about numbers and their factors. You can almost picture the hallway, the first student swinging every door wide, and the ripple of toggles that follows, each step bringing you closer to a surprisingly tidy answer.
One hundred students each toggle lockers in sequence, with the first student toggling every locker, the second every second locker, and so on. After all 100 passes, only the lockers with perfect square numbers remain open. These are the ten lockers: 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100.
- The puzzle takes place in a school hallway with 100 lockers, numbered 1 through 100.
- Each of the 100 students toggles lockers in a specific pattern, with student number n toggling every nth locker.
- A locker ends up open only if it is toggled an odd number of times.
- Only perfect square numbers have an odd number of factors, which is why they stay open.
- The ten lockers left open are 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100.
The Principal's Evening Ritual Meets a 100-Student Prank
Picture a school corridor lined with exactly 100 lockers, each one identical and neatly shut. Every evening, after the last bell rings and the hallways fall quiet, the principal walks the length of that corridor to make sure every single locker door is closed. It's a small ritual, a final check before heading home. One day, though, 100 students decide the principal deserves a surprise.
Their plan unfolds in perfect sequence. The first student in line walks down the corridor and opens every locker, all 100 of them. The second student follows, starting at locker number 2, and closes every even-numbered locker. The third student starts at locker 3 and toggles every multiple of 3: if it's open, they close it; if it's closed, they open it. The fourth student does the same for multiples of 4, the fifth for multiples of 5, and so on, all the way down to the 100th student. By the time the last student finishes, the corridor is a jumble of open and closed doors. The question hangs in the air: which lockers will the principal find open the next morning?
Before diving into the answer, it's worth grabbing a pencil and paper. The pattern is right there, but you have to poke around a bit to see it. Consider locker number 24. Student 1 opens it. Student 2 closes it. Student 3 opens it. Student 4 closes it. Student 5 skips it entirely. The students who touch locker 24 are exactly the numbers that divide 24 evenly: 1, 2, 3, 4, 6, 8, 12, and 24. Every time a student toggles it, the door flips. So the final state of any locker comes down to one thing: how many factors its number has.
Most numbers have factors that pair up neatly, which means an even count. But some numbers have a factor that pairs with itself, giving them an odd number of factors. Those numbers are the perfect squares. So the lockers left open are precisely the squares from 1 to 100: 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100. When the principal walks in the next morning, those ten doors will be standing wide open, a quiet math joke that 100 students pulled off together.
Tracking the Toggles: The Locker Puzzle's Hidden Pattern
The key to cracking the locker puzzle is to stop thinking about what each student does and start thinking about what happens to a single locker. Take locker 24. It gets touched by student 1, who opens everything. Student 2 comes along and closes it. Student 3 opens it again. Student 4 closes it. Students 5 and 7 walk right past it. But students 6, 8, 12, and 24 all take their turn flipping it. That is eight total touches.
Those eight students share one thing in common: their numbers are the divisors of 24. Every locker gets toggled exactly once for each of its factors. And just like that, the puzzle stops being chaos and becomes simple arithmetic.
Now watch what happens with small numbers. Locker 1 has only one divisor, student 1, so it gets opened once and stays open. Locker 2 has two divisors, students 1 and 2. The first opens it, the second closes it, and it ends shut. Locker 3 follows the same pattern: opened by 1, closed by 3, finished closed.
Locker 4 tells a different story. Its divisors are 1, 2, and 4. That is three touches. Open, close, open. It survives the night wide open. The pattern snaps into focus: when the divisor count is even, the locker ends closed. When it is odd, the locker ends open.
So which numbers have an odd number of factors? Most numbers pair their factors neatly. The factors of 24 line up as (1, 24), (2, 12), (3, 8), and (4, 6). Four pairs, eight factors, even count. But a perfect square breaks the pairing. Consider 16: its factors are (1, 16), (2, 8), and (4, 4). That middle pair collapses into a single factor because 4 times 4 uses the same number twice. Three factors, odd count, locker left open.
That is the hidden signature the principal finds the next morning. The only lockers standing open are the perfect squares from 1 to 100: 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100. Ten lockers, all with that odd factor count, all quietly announcing the mathematical prank that unfolded overnight.
Why Perfect Squares Win the Locker Puzzle
The ten lockers left swinging open belong to the perfect squares: 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100. That tidy list is the entire answer to the locker puzzle, and it all comes down to counting factors. Once you see why factors decide the fate of each door, the pattern clicks into place.
Think about locker number 24. It gets touched by students 1, 2, 3, 4, 6, 8, 12, and 24, exactly the numbers that divide 24 evenly. That is eight touches total, an even count. Since the first student opens it and every touch after that flips its state, an even number of touches means the door ends up closed. Most numbers behave this way because their factors naturally pair up. For 24, the pairs stack neatly as (1, 24), (2, 12), (3, 8), and (4, 6).
But some numbers refuse to pair cleanly. Take 16. Its factors are 1, 2, 4, 8, and 16. The middle factor, 4, pairs with itself, so it only gets counted once. That leaves 16 with five factors, an odd count, which means an odd number of touches. The door gets flipped an odd number of times and finishes open. Numbers with this self-pairing middle factor are perfect squares, and they are the only ones that pull this trick off.
So when the principal walks in the next morning, those ten doors stand open while the other ninety stay shut. The pranksters had no idea their game would line up so neatly with square numbers, but that is exactly what the math promises.
Frequently asked questions
What is the locker puzzle?
The locker puzzle is a classic math riddle set in a school hallway with 100 lockers and 100 students. Each student walks down the hall in turn, toggling the state of every locker whose number is a multiple of their own. The question asks which lockers remain open after all 100 students have taken their turn.
Why do only perfect square lockers stay open?
Perfect square lockers stay open because they have an odd number of factors. Every time a student toggles a locker, it changes state, so a locker toggled an even number of times ends up closed. Only numbers with an odd count of factors, which are precisely the perfect squares, receive an odd number of toggles and finish open.
How does the toggling sequence work?
Student number n toggles lockers n, 2n, 3n, and so on, up to 100. For example, student 3 touches lockers 3, 6, 9, 12, and continues through every multiple of 3. Each locker gets toggled once for every factor its number has, which is why the factor count determines the final state.
Which lockers are open after 100 students?
The open lockers are 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100. These ten numbers are the perfect squares between 1 and 100. Each one has an odd number of factors, so each gets toggled an odd number of times and ends the prank standing open.
What is the mathematical explanation?
A locker ends open if it has an odd number of factors. Factors naturally come in pairs, like (1, 24) and (2, 12) for the number 24. But when a number is a perfect square, its square root pairs with itself, leaving an unpaired factor and an odd total count.
Did the principal find any lockers open?
Yes, the principal found ten lockers open when arriving at school the next morning. The ten perfect-square lockers, from 1 through 100, were the only ones left open after all 100 students completed their toggling sequence. Every other locker had been toggled an even number of times and sat closed.
How can I solve the 100 locker riddle?
You can solve it by counting factors for each locker number, or by simply listing the perfect squares up to 100. Take locker 24 as an example: students 1, 2, 3, 4, 6, 8, 12, and 24 all touch it, which is eight toggles, so it ends closed. Check each number this way, and the pattern emerges quickly.
What are the factors of a perfect square?
The factors of a perfect square come in pairs except for the square root itself. Take 16: its factors are (1, 16), (2, 8), and (4, 4), giving three distinct factors total. That single unpaired factor is what makes the count odd and the locker stay open. Editorial note: Any facts which remain unconfirmed are presented as such, hedged with appropriate caution.
Got a take on this? Add your voice to the conversation below →
No comments yet. Be the first.