Andy was a young, successful banker who was wrongly convicted of murdering his wife and her lover based on circumstantial evidence. Andy was incarcerated at Shawshank Prison in 1948, where he wore the prisoner number 81433-SHNK. Andy would later be forced by the warden to handle his money laundering from cash illegally skimmed off the top of community service projects. Andy created a false identity for the money to be traced back to and was involved in a number of projects at the prison, including making the Brooks Hatlen Memorial Library. Andy became friends with most of the inmates, although his best was Ellis Boyd Redding, who he called "Red". Red, who could secretly deliver almost any kind of contraband into the prison, agreed to get Andy a rock hammer so he could continue with his geology hobby, by carving rocks into small objects like chess pieces. Andy would later take a pupil named Tommy Williams under his wing so he could get his GED. However, when Tommy revealed that he knew who really murdered Andy's wife, he tried to testify on Andy's behalf, only to be murdered by the warden's head guard, Byron Hadley, so Andy wouldn't tell about the corruption the warden was involved with. Andy then decided to make a daring escape he was planning, where he escaped in a small hole he had been digging over the course of twenty years with his small rock hammer. He exposed the warden's corruption, and shortly afterward, the warden committed suicide to avoid being locked up in the prison with a bunch of angry convicts. Andy escaped to a small town in Mexico called Zihuatenejo, where he started a hotel business and began the process of fixing up an old boat. As soon as Red was paroled, he gave Red instructions and money on how to get to him, and the two lifelong friends embraced.
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.
As a free man, Andy had been a rock-hound, and now he has immense amounts of free time on his hands, so he asks Red to get him a rock hammer, a tool he uses to shape the rocks he finds in the exercise yard into small sculptures. 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.
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, at no charge, of course. He quickly becomes a valuable asset to the prison staff.
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 cell mate 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.
The warden of Shawshank, Norton, also realizes that a man of Andy's skills is 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 details 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 hidden under a black rock 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 Mexico. 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.
One morning after he has been incarcerated for nearly twenty-seven years, Andy literally disappears from his locked cell. 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 twenty years, through the wall. Once through the wall, he broke into a sewage pipe by syncronizing his strikes with lightning, before crawling 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 called Fort Hancock, Texas, near the Mexican border, and surmises that Andy crossed the border there.
Under this rock, he finds a letter addressed to him from "Peter Stevens" inviting him to join Peter at the town he had told him about. With the letter are twenty fifty dollar bills ($1000). The story ends with Red violating his parole to follow Andy to Mexico.