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.
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 named Byron Hadley griping over the amount of tax he will have to pay inheritance from his estranged brother. Andy approaches Byron, 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. Hadley agrees and Andy later begins doing taxes at no charge for the entire prison staff, later being moved out of the laundry by the warden himself.
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". 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.
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.
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. Red later finds the tin that Andy told him about and inside finds a letter addressed to him from "Peter Stevens" inviting him to join him at the town he had told him about. With the letter are twenty fifty dollar bills ($1000), and Red leaves to follow Andy to Mexico.