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. Andy is befriended by contraband smuggler, Ellis "Red" Redding, an inmate serving a life sentence. Red procures a rock hammer and later a large poster of Rita Hayworth for Andy. Working in the prison laundry, Andy is regularly assaulted 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 legally shelter the money. After an assault by the Sisters nearly kills Andy, Hadley beats Bogs severely. Bogs is then transferred to another prison. Warden Samuel Norton meets Andy and reassigns him to the prison library to assist elderly inmate Brooks Hatlen. Andy's new job is a pretext for him to begin managing financial matters for the prison employees. As time passes, the Warden begins using Andy to handle matters for a variety of people, including guards from other prisons and the warden himself. Andy begins writing weekly letters asking the state government for funds to improve the decaying library.
In 1954, Brooks is paroled, but cannot adjust to the outside world after fifty years in prison, and commits suicide by hanging himself. Andy receives a library donation that includes a recording of The Marriage of Figaro. He plays an excerpt over the public address system, resulting in him receiving 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. He has Andy launder the money using the alias Randall Stephens.
In 1965, Tommy Williams is incarcerated for burglary. He is befriended by Andy and Red, and Andy helps him pass his GED exam. In 1966, Tommy reveals to Red and Andy that an inmate at another prison claimed responsibility for the murders for which Andy was convicted. Andy approaches Norton with this information, but he refuses to listen and sends Andy back to solitary confinement when he mentions the money laundering. Norton has Hadley murder Tommy under the guise of an escape attempt. Andy declines to continue the laundering, but relents after Norton threatens to burn 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 tells Red of his dream of living in Zihuatanejo, a Mexican coastal town. Red feels Andy is being unrealistic, but promises Andy that if he is ever released, he will visit a specific hayfield near Buxton, Maine, and retrieve a package Andy buried there. He worries about Andy's well-being, especially when he learns Andy asked another inmate to supply him with six feet (1.8 meters) of rope.
The next day at roll call, the guards find Andy's cell empty. An irate Norton throws a rock at the 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 escaped through the tunnel and prison sewage pipe, using the rope to bring with him Norton's suit, shoes, and the ledger containing details of the money laundering. While guards search for him, Andy poses as Randall Stephens and visits several banks to withdraw the laundered money, then mails the ledger and evidence of the corruption and murders at Shawshank to a local newspaper. FBI agents arrive at Shawshank and take Hadley into custody, while Norton commits suicide by shooting himself to avoid his arrest.
After serving forty years, Red is finally paroled. He struggles to adapt to life outside prison and fears 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 and travels to Fort Hancock, Texas to cross the border to Mexico, admitting he finally feels hope. On a beach in Zihuatanejo he finds Andy, and the two friends are happily reunited.

Question: How long does it take Red to leave prison?
Answer: 40 years