5 Gallon 3 Gallon Riddle: Walkthrough & Solution (2026)
Stuck on the 5-gallon 3-gallon riddle? Here is the full step-by-step solution, both methods, and the simple math that makes it work.
Posted August 5, 2026

Join a livestream
Learn from top experts and industry experts in live, interactive sessions you can join for free.
Table of Contents
You have a five-gallon jug, a three-gallon jug, and a water source with no measuring lines anywhere. Your job is to measure out exactly four gallons of water. That is the whole 5-gallon 3-gallon riddle, and the short answer is yes, it can be solved in six steps, with no guessing.
Fill the 5-gallon jug. Pour water into the 3-gallon jug until it is full, which leaves 2 gallons in the larger jug. Empty the 3-gallon jug, then pour those 2 gallons into it. Fill the 5-gallon jug again and top off the 3-gallon jug, which only has room for 1 more gallon. You are left with exactly 4 gallons in the 5-gallon jug.
If that felt fast, do not worry. The rest of this article walks through every step slowly, shows a second method, explains the mathematics behind why it works, and clears up the one step that trips up almost everyone. By the end, you will understand not just the answer but the process that gets you there.
Where the Riddle Comes From
Most people know this puzzle from one movie. In Die Hard with a Vengeance (1995), the villain Simon forces Detective John McClane and his reluctant partner Zeus Carver to disarm a bomb by measuring precisely four gallons of water using two jugs and a fountain. Get it wrong by an ounce, and the bomb goes off. The scene became so well known that the puzzle picked up a nickname, the "Die Hard puzzle," even though the water jug problem itself is much older than the film.
The riddle belongs to a family of classic brain teasers called water pouring puzzles, and this version was featured in the film as a life-or-death test. They show up in math classes, coding interviews, and puzzle books because they reward a specific kind of thinking. Worth a note before you start: you cannot brute force your way to the answer by eyeballing the water. You have to plan a sequence of moves.
The Rules Before You Start
The setup is simple, but the constraints are what make it a challenge. Here is exactly what you are working with.
You have two jugs, one 5-gallon jug and one 3-gallon jug. Neither jug has any markings, so you cannot measure a partial amount by looking. You have an unlimited water source to fill from and somewhere to dump water out. Your only legal moves are to fill a jug to the top, empty a jug completely, or pour water from one jug into the other until either the first jug runs out or the second jug is full.
That last rule is the important one. Because you can only pour until a jug is full or empty, every pour gives you a known, exact amount. That is what lets you measure four gallons of water without any lines on the jugs.
Method 1: The Fill the 5-Gallon Jug First Approach
This is the method McClane uses in the movie, and it is the one most people find easiest to follow. Read each step and picture where the water sits.
- Step 1 - Fill the 5-gallon jug all the way from the water source. The 5-gallon jug now holds 5 gallons. The 3-gallon jug is empty.
- Step 2 - Pour water from the 5-gallon jug into the 3-gallon jug until the smaller jug is full. You just moved 3 gallons across, so 2 gallons are left behind in the 5-gallon jug.
- Step 3 - Empty the 3-gallon jug completely, dumping its contents back into the source. Now pour the 2 remaining gallons from the 5-gallon jug into the empty jug. The 3-gallon jug holds 2 gallons, and the 5-gallon jug is empty.
- Step 4 - Fill the 5-gallon jug again, all the way to the top. You now have a full 5 gallons in one jug and 2 gallons sitting in the other jug.
- Step 5 - Pour water from the full 5 gallon jug into the 3 gallon jug. The 3-gallon jug already holds 2 gallons, so it only has room for 1 more gallon before it overflows. Transferring water across stops after exactly one gallon, giving you your target in the larger jug.
- Step 6 - Stop. The 3-gallon jug is now full at 3 gallons, and the 5-gallon jug holds exactly 4 gallons of water. That is your answer.
Here is the same sequence as a table, which helps if you like to track the state of each jug at every step.
| Step | 5 Gallon Jug | 3 Gallon Jug | Action Taken |
|---|---|---|---|
| Start | 0 | 0 | Both jugs empty |
| 1 | 5 | 0 | Fill the 5 gallon jug |
| 2 | 2 | 3 | Pour into the 3 gallon jug until full |
| 3 | 0 | 2 | Empty the 3 gallon jug, then transfer 2 gallons in |
| 4 | 5 | 2 | Fill the 5 gallon jug again |
| 5 | 4 | 3 | Top off the 3 gallon jug, leaving 4 gallons |
The One Step That Confuses Everyone
If you scroll the comment sections on any page where people post about this puzzle, the same step trips them up over and over. It is step 3, where you empty a jug that already has water in it and then move a different amount of water into that same jug.
One example from a Reddit comment put it plainly. The person followed the fill and pour moves fine, then hit the point where you dump the 3-gallon jug and refill it with the 2 leftover gallons, and it stopped making sense. That instinct to hold onto water you already measured is exactly what blocks the solution.
The mental unlock is this. The 3-gallon jug is not a place to store your answer. It is a measuring tool. Transferring water into it carves off known amounts, 3 gallons here, 1 gallon there, with each 3-gallon jug leaving a precise remainder in the larger jug. Emptying the small jug feels like going backward, but it is the move that sets up the final pour. Once you accept that the 3-gallon jug will get filled and emptied several times, the whole sequence clicks.
Method 2: The Fill the 3-Gallon Jug First Approach
There is a second valid path to the answer, and it works just as well. Some people find it more intuitive because you start with the smaller jug. This is the other solution puzzle fans point to in almost every online thread.
- Step 1 - Fill the 3-gallon jug and pour all of it into the empty 5-gallon jug. The 5-gallon jug holds 3 gallons.
- Step 2 - Fill the 3-gallon jug again. Pour water into the 5-gallon jug until it is full. The 5-gallon jug can only take 2 more gallons before it is full, so 1 gallon stays behind in the 3-gallon jug.
- Step 3 - Empty the 5-gallon jug completely. Pour the 1 gallon from the 3-gallon jug into the now empty 5-gallon jug. The 5-gallon jug holds 1 gallon.
- Step 4 - Fill the 3-gallon jug one more time and pour all 3 gallons into the 5-gallon jug. That 1 gallon plus 3 gallons gives you exactly 4 gallons of water.
Both methods reach the same finish. Method 1 leaves your four gallons in the 5-gallon jug after fewer total moves, so if speed matters, that is the one to reach for. Method 2 is a good backup if you lose track partway through the first sequence.
The Math That Makes It Work
The riddle is not luck. It is number theory in disguise, and once you see the pattern, you can solve versions with any jug sizes.
Every move you make adds or removes a full jug of water, either 5 gallons or 3 gallons at a time. So the amount you can reach is any combination of fives and threes added and subtracted. Written as an equation, you are solving for whole numbers in the form of 5x − 3y = 4.
Method 1 is the case where you fill the 5-gallon jug twice and empty the 3-gallon jug twice. Plug that in, and you get 2 times 5 minus 2 times 3, which is 10 minus 6, giving you 4. The two jugfuls of volume you poured out through the small jug leave four gallons behind. Method 2 is the mirror image: 3 times 3 minus 5, which is 9 minus 5, also 4.
The reason any of this is possible comes down to the greatest common divisor. The greatest common divisor of 5 and 3 is 1, because no whole number larger than 1 divides evenly into both. When the greatest common divisor of your two jugs is 1, you can measure out every whole number of gallons from 1 up to the size of the larger jug. Four gallons is on that list, so a solution exists.
This is also why some jug pairs fail. If you had a 6-gallon jug and an 8-gallon jug, their greatest common divisor is 2, so you could only ever measure even amounts. Four gallons would still be reachable there, but three gallons would be impossible no matter how you poured.
Is It Really Exactly 4 Gallons?
Here is a fair objection people raise, and it is worth being honest about. In the real world, could you truly hit exactly four gallons?
As a pure logic puzzle, yes. The math is exact, and every pour moves a precise, full jug amount. As a physical task with real jugs, it is messier. Over on the Reddit ELI5 thread, one commenter raised the sharpest version of this. Simon never told McClane and Zeus where to fill the jugs to. If the intended fill mark sat at the base of the neck instead of the very top edge, all that careful pouring could still leave you short, and the bomb goes off anyway. Another person in the same thread put it bluntly: a real bomb needing exactly four gallons would have detonated, because you can get close but not perfect once spills, drips, water clinging to the sides, and jugs that miss their stated capacity creep in.
That is the honest gap between the puzzle and the kitchen. The riddle assumes ideal conditions, clean pours, and jugs that hold exactly what they claim. That assumption is what lets the answer be clean. You can see the same tension in the answers on Quora, where several people note the solution only holds if you are allowed to pour out and discard water freely at each step, with no waste. In the movie, the bomb going off on a rounding error is played for tension. The brain teaser itself lives in the world of perfect measurement, not messy fountains.
Why This Riddle Is Worth Your Time
Beyond being a fun challenge, the 5-gallon 3-gallon riddle trains a way of thinking that transfers well.
It rewards working backward from a goal, breaking a problem into known sub-steps, and tracking state carefully so you do not repeat yourself. Those are the same habits that help you figure out a bug in code, plan a project, or work through any problem where the path is not obvious at the start. The same logic drives real work in science and engineering, where measuring exact amounts from limited tools is a daily task. That is a big reason the puzzle keeps showing up in technical interviews and math classrooms decades after the movie made it famous.
If you enjoy the mental workout of untangling a problem like this, that same instinct for structured thinking is exactly what pays off in a career, whether you are prepping for graduate school, moving into a competitive field, or aiming for a promotion. A good coach can help you apply that structured problem-solving to the real decisions in front of you.
Final Thoughts: The Real Lesson Hiding in 2 Jugs
Strip away the bomb and the movie, and the 5-gallon 3-gallon riddle is a lesson in constraint. You are handed two blunt tools, no markings, and a target that neither jug can hold on its own. The answer does not come from a better tool. It comes from sequencing the moves you already have until the constraint works in your favor. That is the whole trick, and it is why the puzzle outlives the film that made it famous.
The same shape shows up in real decisions. You rarely get the perfect option handed to you. You get a few imperfect ones and a goal that none of them reaches directly, and the win goes to whoever sequences their moves well. Learning to see the path instead of the obstacle is a skill, and like any skill, it sharpens fastest with someone experienced pointing out the step you keep missing, the same way a good explanation unlocks step 3 of this puzzle in seconds.
Put That Thinking to Work
If you want that kind of guidance for your own career, Leland connects you with people who have already solved the problem you are staring at. Book a one-on-one session with a career development coach for direct feedback on your next move, join a free live career event to learn from top experts in real time, or go deeper with a structured career development bootcamp. Start with a free intro call and figure out the path that fits you.
See: Top Career & Leadership Coaches
Top Coaches
Read next:
- How Many Pigs Are in China? | McKinsey Brain Teaser Answered
- How to Build Your Career Outside of the US
- To Be a Jack of All Trades or Master of One?
- The Role of Mentors: How Guiding Relationships Can Shape Your Career
- How Long Does It Take to Hear Back from a Job? What to Expect and What to Do Next
FAQs
What is the answer to the 5-gallon 3-gallon riddle?
- Fill the 5-gallon jug, pour it into the 3-gallon jug to leave 2 gallons, empty the 3-gallon jug and transfer those 2 gallons in, refill the 5-gallon jug, then top off the 3-gallon jug. That leaves exactly 4 gallons of water in the 5-gallon jug.
Is there more than one way to solve it?
- Yes. You can start by filling the 5-gallon jug, or you can start by filling the 3-gallon jug and building up to 4 gallons in the larger jug. Both methods reach the same result.
What movie is the water jug riddle from?
- The puzzle became famous in Die Hard with a Vengeance (1995), where Detective John McClane and Zeus Carver solve it to stop a bomb. The water jug problem itself predates the film by a long time.
What is the math behind the riddle?
- It solves the equation 5x − 3y = 4 using whole numbers. Because the greatest common divisor of 5 and 3 is 1, you can measure any whole number of gallons up to 5, which includes 4.
Can you solve it with different jug sizes?
- Only if your target is a multiple of the greatest common divisor of the two jugs. Two jugs of 6 and 8 gallons share a greatest common divisor of 2, so you could measure even amounts but never an odd number like 3.
























