The Two Generals’ Problem

Tom Scott

Tom Scott

1 688 515 Views1 052

    Time to tell a story about idempotency, computer science, and the Night of the Multiple Orders. • Sponsored by Dashlane -try 30 days for free at:
    Written by Sean M Elliott and Tom Scott
    Directed by Tomek
    Graphics by Mooviemakers
    Audio mix by Haerther Productions
    Thanks to Dashlane for sponsoring the video! If you're techie enough to watch this video, you should be using a password manager. Get a 30-day free trial at
    I'm at
    on Twitter at
    on Facebook at
    and on Instagram as tomscottgo

    Published on 4 months ago


    1. Tom Scott

      Yes, I had help with the graphics for this series. There's no way I'd have animated that myself! On that note, thanks to Dashlane for sponsoring and helping me hire an animator: their free trial link is

      1. Akin Turhan

        I have thought about dashlane I want to know the advantage over Google chrome random password generator and manager that is synced with one master password. they don't know any of the passwords either.

      2. The Superginge

        As glad as I am that you're getting sponsored, I feel I should tell people that Firefox is starting to offer this password security option for free, though before anyone gets angry at me, I don't know what level of security it is, comparatively, I just want to make people aware of options!

      3. Matti Lüdke

        Why not send a person from each army to the middle of the valley. Then both discuss a time and go back to their army. That way they will know if the message was received by the other army. As the Danger of the route lies in the middle of the valley they will get back safely.

      4. صالح

        Hey there is a way to solve the 2 genrals problem and it's a horne or war drums because they are loud enugh to hear

      5. Dark Thoughts

        Now you know the issues protocol standards committees have to 'foresee' when designing a communication protocol.

    2. jahaziel herrera

      Just siege them

    3. That Asshole

      Couldn’t the red army reposition?

    4. DiabloMinero

      General A sends the entire army over to B's side by labeling one soldier at a time as a "messenger" and sending them over. The majority of the army gets through. They now have a combined army with roughly twice the strength of the original armies and no longer have the valley in the middle. They can agree on a time to attack and then attack.

    5. Narobii

      Tom, please don't cook yourself. self cannibalism isn't good.

    6. Notecnirp

      Can’t the messenger come back and say that the other side got the message??

    7. Norm

      couldn’t the general of army a just wait until his messenger got back with a piece of paper that says “acknowledged”

      1. freddy46

        How can they know if the "acknowledged" message came through?

    8. Right Wing Safety Squad

      I know this doesn't work for the case of computer networking, but if General A takes his entire army to General B, surely then they'd all know when to attack ;)

    9. Gerald Wiseman

      2:11 in and thinking of a solution before it's (presumably) given. Here's the theory: Group A makes many identical messages, one for each messenger they have. Each message includes three bits of data -- the coordinated attack time, a continuous acknowledgement request, and the information that at some designated time prior to the coordinated attack time, Group A will cease sending messages so long as they've received Group B's acknowledgement, and that should messages be received from Group A after that time, Group B should know the attack is off. This means Group A periodically sends these messages. And should any messenger come from Group B, their arrival implies an agreement on the attack. At this point both groups need no further information. Because Group A knows that Group B agreed upon the time, and Group B doesn't need any other messages to be sure that Group A received one of their messages. In fact, the only way Group B will know that Group A HASN'T gotten their message is if they receive another message after the previously expressed "halt" time. And neither group is in danger of attacking without the other because for both parties to receive any message at all it means all is going according to plan. And if either group doesn't receive a message, or if they receive a message after the established time, they will definitively know something went wrong.

    10. Mochacocoa

      Isn't it solved in three messengers? Messenger 1A tells general B about the time to attack. Messenger B tells general A that the time is agreed upon. Messenger 2A tells general B his confirmation was received and they're preparing for the agreed upon time. Then they both know the other has agreed to attack at the stated time.

      1. Frederik Carl

        "Magical computer science, infomation theory land"

    11. Justin Moore

      Both armies surround the castle and starve the castle of resources. No messages needed. The street creepers and 4 chan have won. Just like the alamo I am going to troll until the end.

    12. Federico Olivares

      To me is simple the general's problem A sends "is 8pm ok? Send "ok" back for yes, if you dont receive an ok back from me, send "response?" Back 2 more times. If you dont get an ok from me, consider it null. I too will send a 2 "response?" If i dont listen back So gen B agrees, Sends one Ok gets Ok back Both attack. Gen b sends ok doesnt hear back, received "response?" Sends ok Receives ok both attack Gen b sends ok doesnt hear back, doesnt receive response at all. Asumes A's ok has been intercepted as they would have sent one or more "response?" Back otherwise. Sends "response?" And so on. If all 5 messagers get caught after the initisl messsge, the attsck wouldnt go through. If just 2 Oks do go through, the attsck goes through

    13. Phillip Otey

      I mean you need 2 minimum. A keeps sending troops saying: send one troop telling us what time to attack. We will keep sending troops until the package is received, and if the time of attack has not past we are a go.

    14. Ady Day

      Don’t rely on technology too much..nothing is built to last!

    15. Name

      Just make an agreement that 2 or more acknowledgements means you can attack

    16. Jo 1337

      It's 2 am and I regret nothing

    17. Vysair

      Or maybe both general could send dozen more message until it hit certain threshold and that will confirm it.

    18. 10k12

      2:35 why not let them meet in the middle, so if they perish, they perish together and no message is received, but if they manage to meet, they can return and there are no threats on the way back to the generals.

    19. Shaurya Pant

      Well, after both the teams have received confirmation of the other party that they know that you know and will go at 8PM, I don't see any further need of sending messengers. Can someone explain, please?

    20. Andre L

      How come this problem exists at all, if the proposed time is 8 pm, and both of them acknowledged the acknowledgments, then why would A and B need to keep sending acknowledgments? They both acknowledged the proposal and acknowledgment, so it's already planned? They both already know that it made it to the other side at least twice, so what's the problem? This just feels like it's not really a problem.... How is this line of reasoning incorrect?

    21. Markus B

      I should be asleep but general B didn’t give me a confirmation

    22. john wick

      Simply. General A sends a messenger which returns after delivery of the message. If the messenger does not return after a suitable time span. It is safe to assume something happend and another messenger needs to be sent

    23. Space Griffin

      but wouldn't a and b know they've received the message by the third message?

    24. DukeOfEarle88

      £7.74 word.

    25. UberKrassMann

      2:55 starts sweating.....

    26. Skepty

      Just tell them to make a fire signal after they do, as confirmation. Not that hard.

    27. Ashor

      for the two generals, couldnt one side send a messenger with the message telling them to attack at a certain time (sundown) but to ensure they both know they both have to shoot a cannon ball to the west of the other general at sunrise) if they both observe the cannon ball west of them then they know they will attack at sundown

    28. Midhunraj R Pillai

      I wonder how the generals problem is unsolvable. Please correct me whats the mistake of the solution below, Step1: General A sends message saying attack at 6pm (Here, A establishes the time) Step 2: General B gets the message, sends back an acknowledgement 1 for the message 'we go the time' (B gets the time) Step 3: General A gets the ACK 1 (now, A knows that B got the time of attack. But B won't attack because B don't know that ACK 1 is reached at A. so..) A sends a confirmation ACK 2 back Step 4: General B gets the ACK 2 (now, B knows that both A and B establishes the time. Also B got the ACK 2, meaning B knows that ACK 1 reached A. But B knows that A won't attack until A confirm that B got the ACK 2. so...) B sends a confirmation ACK 3 back Ahhhh this trend continues and no one will attack since they cannot make sure that the previous ACK sent by them is reached at the other end!!! I am sorry (T_T)

    29. Ivan farlenkov

      Have generals send messagers at set periods of time even when there is nothing to send. If there is no messager, ask about it in the next message.

      1. Gareth H

        @Ivan farlenkov You really do not get it. Oh well, nevermind. Stick to flipping burgers.

      2. Ivan farlenkov

        @Gareth H Why not? If messagee is lost, request to resend will be eventualy get to the other side.

      3. Gareth H

        That is the ping approximation that is used. But it is not a solution to the problem, there is no solution.

    30. Monsieur P.

      My bank card would’ve texted me to confirm charge after being pinged to debit my account identical amount of money. It’s kind of stupid that nobody selling the food didn’t notice.

    31. Monsieur P.

      😂 these damn apps!

    32. novicetheaf

      This is a classic lack of dev testing prior to sending it for testing prior to deploying it to the end user, and QA testing.

    33. Kevi Kiru

      Even your paid promotions are interesting to listen to!

    34. Oasia

      Why dont the say just to fire a cannon if they recieve the message

    35. Julian Danzer

      2:57 umm...

    36. Floofzy Kitty

      1:38 What are you talking about? Of course they made it to the other side. Just not the side they intended.

    37. Muhammad Adam

      Surely after the 4 messengers they wouldn't need confirmation any further confirmation because both would have already known that it's agreed upon

    38. Terrain

      You didn’t solve the two generals problem, you solved another problem created by it being unsolvable, which arguably is more dangerous than the two generals problem

    39. BeforeReform

      per your ad... there is *always* the possibility of brute force getting through. It could take years, or decades on average, but there is always a chance someone gets lucky.

    40. Angelmarauder


    41. its_a_trab

      You could just send the original guy back.

    42. Emerald Block Boat

      I'd say that if B received two verifications then do it

    43. TARINunit9

      Proposition for the two generals problem: instead of sending one messenger, send a pair of messengers. One messenger stays at camp B and the other returns to camp A. If no messengers return to camp A, then it's obvious that the message was intercepted on one of the two trips, so you send another pair

    44. Lloyd Thorpe

      What they should have done is just starve the castle out like they most commonly did

    45. The Nintendo Fan

      Honestly, the red army would automatically assume the blue army got the message and would attack on that time

    46. Eric ON

      Atleast once invocation solves this issue as well. I.e. let the client keep spamming the same request until one confirm has been recieved.

    47. Emil Sørensen

      I'd definitely not like having a master password that, if lost, renders my entire online life unrecoverable. How can you possibly make your one password unforgettable? Chisel it into an immovable rock?

    48. ͔ ͔

      Send the entire army as the messenger

    49. Beowulf Macbethson

      I was watching a video about Morgoth from Lord of the Rings, why am I here. Also your video is great and informative.

    50. TIMΞ СнΛИGΣ

      But the generals would know after a few acknowledgements? What am I missing here

    51. andrew allen

      Good grief, a Hewlett-Packard computer I can do component level repairs and maintenance on!

    52. man0z

      I may have double paid for Nandos last night

    53. IlluminatiBG

      We solved this problem for banking application at work. The app is designed to work offline and synchronize when online. The acknowledgment problem is that you do not know if a message did not reach the server or it reached the server, but the confirmation was lost. As a result each message is uniquely identified in the client and safe to repeat. You can resend a message to the server a million times, but it will result in one transaction only for both client and the server.

    54. Curtis Moore

      This sort of thing happened to me 3 years ago through Amazon. The progress wheel after clicking "Buy Now" kept freezing when I hit it. I foolishly kept refreshing and hitting "Buy Now" again until getting to the confirmation screen. This was why, two weeks later, I had to ship back 15 identical USB phone chargers.

    55. Joshua Anderson

      So how does general A know that general B got the message?

      1. Joshua Anderson

        @lorvincent Thank you but I'm still not getting it for some reason. Are you saying that general A and B have 1000 other generals to get messages from? If general B relays the message to 1000 other generals how does general B know the other generals got the message? I'm stuck on something here...

      2. lorvincent

        Because 1000 other generals also got the message, and general B relayed to all 1001 of them, which caused the other 1000 to relay to general A that B got the message. It isn't the method described in the video, but this is the basic idea behind distributed ledgers with byzantine fault tolerance.

    56. Asma Hasmalaria

      I have the solution: Instead of sending messengers to general B, general A picks up his phone, dials the number of the favorite pizzeria and says "I want a valley castle, with cheese dip and onions" and Deliveroo gets nothing while the pizzeria gets the money they deserve.

    57. iHunterKiller

      We’re looking at this as a 2d plane. In 3d, don’t go through the castle, go around it, meet up, attack together. Done.

      1. MrCocktaiI

        Few things are as boring as giving 'clever' answers to puzzles that totally disregard the actual problem

    58. Banned From Existance

      So what if we get two messengers, one tries to go through the valley meanwhile the other observes the messenger at a safe distance. If the message gets killed, the other person can come back to let them know they failed! Thus they keep attempting until the get it right.

    59. BillyViBritannia

      So the actual question is 'can you make sure a message arrives if you can't ensure the message' s arrival?' Well, doesn't take a genius to see why that's impossible.

    60. BillyViBritannia

      How is the comment section of such a technical/educational video so God damn funny.

    61. Jonny boy

      Can quantum computing utilizing quantum entanglement solve this issue?

    62. Solo Playzz

      2 messengers meet in the middle before ya say

      1. Solo Playzz

        Ok so you dont come to this conclusion... I'm gonna get an ego problem

      2. Solo Playzz

        Wait... do you not come to this conclusion??

    63. Lucas nada mas

      What if you want one of the food and then you decide for whatever reason you want another... you cant

    64. MightyGalactus

      What if General A send a messenger to General B with a message. Send a soldier to the middle at 5pm if they meet then the attack will be at 8pm. If they dont the attack will be at 9. After General B confirms that B received the msg from A.

    65. No pe

      Isn't this what Bitcoin is trying to solve for money?

    66. No-Feet McGee

      "If you are in computer science and working on problems that involve potential loss of life, I really hope you aren't watching a series called the Basics." Look, just because you already know something doesn't mean it's not fun to watch an entertaining US-new personality talk about it, okay ;)

    67. David Aykac

      "But I was tired, and i was hungry. As are a lot of their drivers" sheeeeeesh, that was a harsh one xD

    68. jamoecw

      idemptity? before computers it was called an order number. it doesn't solve the 2 generals problem either. this can be solved by a single person as well (the programmer).

    69. BuzzaB77

      Known as the Byzantine problem. How Blockchain solved their ledger tech

    70. Fuddleton

      I feel like there's another answer. What if instead of request/acknowledgement, each sent a request with an expected value, and the value was resent to track closer to the original requested value. When both are independently sending the same value, it's confirmation of receipt for both sides.