Chapter 40: Finally escaping with Jim, Huck and Tom are caught by men with guns, so they all make a run for it. All three of them escape, but Tom is shot in the leg, forcing Huck to go for a doctor. When Jim agrees to stay with the injured Tom, risking his own life, Huck says he knew that Jim was "white inside." Here, the reader sees that Huck truly believes Jim to be a real man, just like any other.
Chapter 41: In town, Huck accidentally bumps into Uncle Silas, and he tells him that he and "Sid" have been looking for the "runaway nigger."
Having gone home with Uncle Silas, Huck realizes that all of their escape items have been discovered, which takes a lot of explaining on his part.
Chapter 42: The next morning, Huck wakes to see that both Tom and Jim have arrived. Tom tells Aunt Sally that he and "Tom" were the ones to free Jim, much to her (and Huck's) shock. Then, also to everyone's amazement, Tom announces that Jim is a freeman, that Miss Watson died two months ago and had set Jim free in her will.
Also during this conversation, Tom's Aunt Polly arrives suddenly, wondering why everyone is referring to Tom as Sid. Thus, both of the boys' covers are blown, and they are forced to admit their true identities.