Bilbo and the dwarves wander through the woods, desperate for food. Just then a party of wood-elves emerges from behind the trees, and captures them all, except for Bilbo, who manages to put on his ring and then follow behind unnoticed as the elves march the dwarves into their city. The dwarves are presented to the Elvenking, who questions them and reprimands them for using his roads and attacking the spiders, thereby disturbing his people. The dwarves are angry with the Elvenking, and they’re imprisoned in separate cells, unaware that Thorin is there as well.
Once again, Bilbo demonstrates his value to the group, evading capture while his companions are marched off to imprisonment. It’s important that Tolkien doesn’t entirely take the dwarves’ side in this passage: the Elvenking is right, after all, to be angry that the dwarves have disturbed the spiders, since he has a responsibility to keep his people safe. Bilbo and the dwarves are hardly perfect—they’re not exactly good guests—and this is largely what makes them such interesting characters.
Bilbo walks, invisible, though the elves’ prison, not wanting to abandon the dwarves. He is cautious, for fear of the guards bumping into him. He wishes that he were back in his hobbit-hole, or that he could send a message to Gandalf, but eventually he realizes that he will have to save the dwarves himself.
Bilbo demonstrates how much he has learned about taking care of himself—though he momentarily wishes he could rely on someone else for help, the direness of his situation encourages him to work alone to free his friends.
After a week or two of searching, Bilbo finds Thorin in a special prison cell; Thorin has been so miserable that he was considering telling the elves about his quest for treasure. Bilbo tells Thorin that the other dwarves are there; and he tells the other dwarves that Thorin is nearby, too. Thorin’s opinion of Bilbo grows quickly. Bilbo also discovers that there is a way out of the prison besides the front gates: there is a canal underneath the building that the elves use to transport barrels of wine.
Thorin gains new respect for Bilbo, just as the other dwarves do. Indeed, Bilbo’s intelligence and resourcefulness seem much more impressive than Thorin’s integrity—he was considering giving up information about the treasure when Bilbo found him.
One night, Bilbo overhears the elves talking about an upcoming great feast, full of wine and revelry. Bilbo seizes the opportunity, and when the guards are drinking upstairs, he steals the keys to the prison cells and frees every dwarf. He tells the dwarves to hurry and be silent as he loads them into barrels; normally the barrels transport wine down the river to trade with the men of Lake-town (which is also called Esgaroth). Now they will carry the dwarves to freedom. Bilbo lowers the barrels into the canal and they float down the river. Bilbo himself is forced to swim in the water, at least until he is able to swim to a barrel and use it as a raft.
There is a childish quality to the dwarves' escape, since they make use of the elves’ drunkenness—an unmistakably adult vice—when they escape. In this chapter, Bilbo has become responsible for the other members of his group, and the end is no exception—he’s forced to swim alongside the barrels.
The barrels run aground at a nearby town, where they’re stored overnight. Bilbo swims ashore and uses his ring to steal some food and wine; the next day, the barrels are sent back along the river, and they float to Lake-town.
Tolkien doesn’t give details about how Bilbo steals food that night—it’s as if Bilbo has grown so competent as this kind of burglary that it’s almost not worth mentioning.