In 1947 Portland, Maine, banker Andy Dufresne is convicted of murdering his wife and her lover and is sentenced to two consecutive life sentences at the Shawshank State Penitentiary. He is befriended by Ellis "Red" Redding, an inmate and prison contraband smuggler serving a life sentence. Red procures a rock hammer and a large poster of Rita Hayworth for Andy. Assigned to work in the prison laundry, Andy is frequently raped by "the Sisters" and their leader, Bogs.
In 1949, Andy overhears the captain of the guards, Byron Hadley, complaining about being taxed on an inheritance and offers to help him shelter the money legally. After an assault by the Sisters nearly kills Andy, Hadley beats and cripples Bogs, who is subsequently transferred to another prison; Andy is not attacked again. Warden Samuel Norton meets Andy and reassigns him to the prison library to assist elderly inmate Brooks Hatlen. Andy begins managing financial matters for other prison staff, guards from other prisons, and the warden himself. He also begins writing weekly letters to the state legislature requesting funds to improve the prison's decaying library.
Brooks is paroled in 1954 after serving 50 years, but he cannot adjust to the outside world and eventually hangs himself. The legislature sends a library donation that includes a recording of The Marriage of Figaro; Andy plays an excerpt over the public address system and is punished with solitary confinement. After his release from solitary, Andy explains that hope is what gets him through his time, a concept that Red dismisses. In 1963, Norton begins exploiting prison labor for public works, profiting by undercutting skilled labor costs and receiving bribes. Andy launders the money using the alias "Randall Stephens".
Tommy Williams is incarcerated for burglary in 1965. Andy and Red befriend him, and Andy helps him pass his GED exam. A year later, Tommy reveals to Red and Andy that his cellmate at another prison had claimed responsibility for the murders for which Andy was convicted. Andy approaches Norton with this information, but Norton refuses to listen and sends him back to solitary confinement when he mentions the money laundering. Norton has Hadley murder Tommy under the guise of an escape attempt. Andy attempts to discontinue the laundering but relents after Norton threatens to destroy the library, remove Andy's protection from the guards, and move him to worse conditions. Andy is released from solitary confinement after two months, and he tells a skeptical Red that he dreams of living in Zihuatanejo, a Mexican coastal town. Andy also tells him of a specific hayfield near Buxton, asking Red to retrieve a package that Andy buried there. Red worries about Andy's well-being, especially when he learns Andy asked a fellow inmate for six feet (1.8 meters) of rope.
At the next day's roll call, the guards find Andy's cell empty. An irate Norton throws a rock at a poster of Raquel Welch hanging on the cell wall, revealing a tunnel that Andy dug with his rock hammer over the last 19 years. The previous night, Andy used the rope to escape through the tunnel and prison sewage pipe, taking Norton's suit, shoes, and ledger, containing proof of the money laundering. While guards search for him, Andy poses as Randall Stephens, withdraws the laundered money from several banks, and mails the ledger and other evidence of the corruption and murders at Shawshank to a local newspaper. State police arrive at Shawshank and take Hadley into custody, while Norton commits suicide to avoid arrest.
After serving 40 years, Red is finally paroled. He struggles to adapt to life outside prison and fears that he never will. Remembering his promise to Andy, he visits Buxton and finds a cache containing money and a letter asking him to come to Zihuatanejo. Red violates his parole by traveling to Fort Hancock, Texas, and crossing the border into Mexico, admitting that he finally feels hope. He finds Andy on a beach in Zihuatanejo, and the two reunited friends happily embrace.