There's some question as to whether Andy or Red is the real protagonist of the story. Near the end of the story, Red claims it's him, not Andy:
"Well, you weren't writing about yourself, I hear someone in the peanut-gallery saying. You were writing about Andy Dufresne. You're nothing but a minor character in your own story. But you know, that's just not so. It's all about me, every damned word of it." (504)
Red has every right to believe his story is about himself, but if you'll forgive us for sounding like some hoity-toity literature professor here for a second…Andy is the true agent of the action in this story. He causes all the trouble, he takes all the steps, and the story is ultimately about how he escapes his confinement. Red sort of trails after him like a forlorn bridesmaid. It's their story, but Andy's still at the center of it.
Andy represents the story's strongest theme: Hope. Red notices that he doesn't act like he's in a prison:
"He had something that most of the other prisoners, myself included, seemed to lack. Call it a sense of equanimity, or a feeling of inner peace, maybe even a constant and unwavering faith that someday the long nightmare would end." (222)
Andy's sense of peace and happiness emanates outward, filling his fellow prisoners with all kinds of warm fuzzies and helping them forget for a time that they're stuck in a little cell. It shows up in places like the library, where Red remembers: "I saw him gradually turn one small room (which still smelled of turpentine because it had been a paint closet until 1922 and had never been properly aired) lined with Reader's Digest Condensed Books and National Geographies into the best prison library in New England" (198). It could also be things like the beer he gets for the tarring crew. The men take a break to drink, and, according to Red: "For those twenty minutes we felt like free men." (191)
Strangely enough, we never really learn why Andy is so optimistic. He doesn't have a lot to be hopeful about, having been wrongly accused of his wife's murder and thrown in jail for the rest of his life. And yet, his sense of hope is so strong and so clear that he keeps it alive for over thirty years as he waits in prison. He also helps the other inmates feel the same way by making little gestures that go a long way: Beer that makes them feel "like free men," and a library that awakens "a hunger for information on such snail hobbies as soap-carving, woodworking, sleight of hand, and card solitaire" (199). Andy helps the other prisoners feel better about their lives and helps them pick up productive hobbies during their time in prison. Andy's not just hopeful; he's contagious. He shares his hope with others around him and makes the world a better place as a result.
Andy is also very clinical and tight-lipped. This helps explain how he got to Shawshank in the first place for a crime he didn't commit. At his trial, the jury freaks out at his coldness, and Red notes:
"I knew him for close to thirty years, and I can tell you he was the most self-possessed man I've ever known. What was right with him he'd only give you a little at a time. What was wrong with him he kept bottled up inside." (20)
Basically, when it comes to Andy, nobody really knows the guy. He's good at keeping secrets. This brings us to one of the book's other major themes: Secrecy. Secrecy helps Andy hold onto his hope, since he knows about some pretty juicy details that others don't, like his escape tunnel, secret identity, and hidden money. He uses these secrets to improve his outlook. Knowing that he's well on his way to make an epic escape from prison is the kind of thing that really puts a spring in Andy's step throughout the story.
Andy's secrecy also speaks to the presence of some very deep emotions that he hides very well. In some ways, he's playing a big poker game with Norton, Hadley and the other authority figures in the prison. He's outsmarting them, outfoxing them, and generally making them look like fools. And the only way to do that is to hide what he's actually thinking. Andy's secrecy may have gotten him into prison, but it also helps him fight back against the bad folks who now control him.
At the same time, his secrecy also lends weight to his friendship with Red. They don't talk much, but when they do, it tends to be about secret things, like contraband. Considering how secretive Andy is, it's a pretty big deal when he tells Red about the hayfield in Buxton where he hid "a piece of volcanic glass, and until 1947 it was a paperweight on my office desk" (364). Telling Red about that piece of glass might have ended any hopes that Andy would get away clean, but he does it as a way of conveying hope to Red that maybe the two of them can get together again in Mexico, outside the prison's walls. That's a pretty strong gesture of friendship right there, made even stronger by the fact that we know how tight-lipped Andy can be.