In 1948, Andy Dufresne arrives at Shawshank Prison. In contrast to most other convicts, Dufresne is not a hardened criminal but a soft-spoken young banker, convicted of killing his wife and her lover. Like almost everyone else in Shawshank, Dufresne insists on his innocence.
Red, the narrator, has an ability to deliver contraband of almost any type (except, on his own principles, hard drugs and weapons) into Shawshank. This makes him an important man within the prison's social structure, and he eventually crosses paths with Andy Dufresne.
As a free man, Andy had been a rock-hound, having an interest in geology, and now he has immense amounts of free time on his hands, so he asks Red to get him a rock hammer, a tool like a small pickaxe he uses to shape the rocks he finds in the exercise yard into small sculptures. Red is leery of the idea at first, thinking Andy will use the tool as a weapon. Andy promises he won't. When Red suggests he might use it to tunnel out of the prison, Andy is amused, sayin Red will understand when he sees the hammer, which is very small. The next item he orders from Red is a large poster of Rita Hayworth. When taking the order, Red reflects that Andy is, quite uncharacteristically, excited like a teenager about the poster, but does not think more of it at the time.
One spring day, Andy and Red and some other prisoners are tarring a roof when Andy overhears a particularly nasty and sadistic guard griping over the amount of tax he will have to pay on a sum of money bequeathed him by a long-estranged brother. Andy approaches the guard, almost getting thrown off the roof in the process, and tells him that he can legally shelter the money from taxation by giving it to his wife as a one-time, tax-free gift.
Andy offers to help the guard to prepare the necessary paperwork for the transaction, in exchange for some beer for the other prisoners on the roof. The guard agrees, and as word of the occurrence spreads, more and more of the prison staff discover that they can use Andy's help for tax returns, loan applications, and other financial advice, free of charge. He quickly becomes a valuable asset to the prison staff, even the warden, who also seeks Andy's advice.
A gang of aggressive homosexual prisoners called "The Sisters", led by Bogs Diamond, gangs up on and rapes any prisoners they feel they can handle, and Andy is no exception. However, when Andy makes himself useful to the guards they protect him from "The Sisters". One night Bogs is found in his cell, 'inexplicably' unconscious and severely beaten. Andy is also allowed to stay alone in his cell instead of having a cellmate like most other prisoners. For a short period, he shares a cell with an Indian called Normaden, but is soon alone again, Normaden having complained about a "bad draft" in the cell.
Andy's work assignment is shifted from the laundry to the prison's small library, then under the stewardship of Brooks Hatlen, one of the few other prisoners with a college degree. Red dryly notes that Brooks' degree is in animal husbandry, "but beggars can't be choosers." The new assignment also allows Andy to spend more time doing financial paperwork for the staff. When Brooks is paroled, Andy takes charge of the library and starts to send applications to the Maine state Senate for money for books.
For a long time he gets no response to his weekly letters until the Senate finally relents, thinking Andy will stop requesting funds. Instead of ceasing his letter writing, he starts writing twice as often. His diligent work results in a major expansion of the library's collection, and he also helps a number of prisoners earn equivalence diplomas, preparing them for life after parole, expanding the base of respectability he has.
The warden of Shawshank, Norton, also realizes that a man of Andy's skills are useful. He has started a program called "Inside-Out" where convicts do work outside the prison for minimum wages. Normal companies outside cannot compete with the cost of Inside-Out workers, so sometimes they offer Norton bribes not to bid for contracts. This cash has to be laundered somehow, and Andy makes himself useful here as well.
One day, Andy hears from another prisoner, Tommy, whose former cellmate had bragged about killing a rich golfer and some hot-shot lawyer's wife (Andy latches onto the idea that the word "lawyer" could easily have been mixed up with "banker", the professions being similarly viewed by the general public), and framing the lawyer for the crime. Upon hearing Tommy's story, Andy realizes that if this evidence could be brought before a court, he could be given a new trial and a chance at freedom.
Norton scoffs at the story, however, and as soon as possible he makes sure Tommy is moved to another, lower security, prison, presumably as compensation for promising that he never talk about this anymore. Andy is too useful to Norton to be allowed to go free, and furthermore he knows every detail about Norton's corrupt dealings. After losing his customary cool with the warden over the issue, and spending a couple of months in solitary as a result, Andy resigns himself that the prospect for his legal vindication has become non-existent.
Before being sentenced to life, Andy managed, with the help of his closest friend, to sell off his assets and invest them under a pseudonym. This made-up person, "Peter Stevens", has a driver's license, social security card, and other credentials. The documents required to claim Peter Stevens's assets and assume his identity are in a safe deposit box in a Portland bank; the key to the box is secreted under a chunk of black obsidian hidden in a rock wall lining a hay field in the small town of Buxton, not too far from Shawshank.
After eighteen years in prison, Andy shares the information with Red, describing exactly how to find the place and how one day "Peter Stevens" will own a small seaside resort hotel in a small Pacific coastal town in Mexico called Zihuatanejo. Andy also tells Red that he could use a man who knows how to get things. Red, somewhat confused about why Andy has confided this information in him, reflects on Andy's continued ability to surprise.
After he has been incarcerated for nearly twenty-seven years, Andy literally disappears from his locked cell, the escape is discovered at the morning count. After searching the prison grounds and surrounding area without finding any sign of an escaped man, the warden looks in Andy's cell and discovers that the poster on his wall (now showing Linda Ronstadt) covers a man-sized hole. Andy had used his rock hammer — and a replacement when the original wore down — not just to shape rocks, but to dig a hole, incredibly painstakingly and over many years, through the wall. Once through the wall, he broke into a sewage pipe, crawled through it for some 500 yards, emerged into a field beyond prison's outer perimeter and vanished. His rock-hammer and prison uniform are found outside the pipe. How he made good his escape with no equipment, clothing, or known accomplices, nobody can determine.
A few weeks later, Red gets a blank postcard from a small town near the Mexican border, and surmises that Andy crossed the border there. Shortly afterwards, Red is paroled. After forty years' imprisonment, he finds the transition to life "outside" to be a difficult process. On the weekends, he hitchhikes to Buxton, searching for suitable hay fields from Andy's "directions".
After several months of wandering the rural town roads, he does find a field with a rock wall on the correct side. At the end of the wall he finds the chunk of obsidian, just like Andy described. Red finds a letter addressed to him from "Peter Stevens" inviting him to join Peter in Zihuatanejo. With the letter are twenty fifty dollar bills ($1.000). The story ends with Red violating his parole but knowing that the authorties probably won't put up much of a manhunt for "an old crook like me." Red wonders if he'll be able to cross the border and see his friend.