WHEN it came to telling the story of Nelson Mandela, screenwriter William Nicholson was faced with almost as many choices as South Africa's first democratically elected president had years on Earth.

The Oscar-nominated writer of Gladiator and Shadowlands could have begun Mandela: Long Walk to Freedom, in 1919, the year after Mandela's birth, when representatives from what became the ANC went to the Paris Peace Conference to plead their case. He could have ended the story when the century's most famous political prisoner walked free. In between, the job of playing Mandela, 95 when he died, had no end of applicants.

"I tried every single way to tell this story," says Nicholson, 65, who first began work on the script 16 years ago. With the casting, as with everything else, one basic rule held: "The big star was Mandela."

That remained the case to the end. In an instance of timing no screenwriter would ever dare contrive, Mandela died on the evening of the royal premiere in London in December.

Justin Chadwick's drama, with Idris Elba starring as Mandela, takes in the grand sweep of Mandela's life, from childhood to presidency and beyond. Much of the delay in bringing the story to the screen was the usual stuff of filmmakers' woes.

"To make a film happen you have to have a script, a director, bankable stars and finance," says Nicholson. "To get those four elements to come together is very difficult."

He at least had a start in Mandela's autobiography. Then there was his own research, which involved going "everywhere", talking to as many people as possible, then starting with a blank page.

"Research is a two-edged sword; you need to know it, and then you need to let it go, otherwise it crushes you under its weight."

The rest was a matter of waiting until the other elements dropped into place. Nicholson admits to "despair" at times, although the novelist, playwright and director remained busy, including co-writing the screenplay for the triple Oscar-winning Les Miserables.

Nicholson had his own connections with South Africa, including grandparents who had lived there before returning to Britain in 1927. Nicholson maintained a strong interest in the country and the plight of the black majority, and in 1992 he co-wrote the screenplay for Sarafina!, the Whoopi Goldberg and Miriam Makeba-starring story of a young woman's political awakening. It was this that was to lead to the commission for Mandela: Long Walk to Freedom.

During the long journey to the screen, many an actor, including Denzel Washington and Will Smith, was linked to the project. "They hadn't been rejected by us," says Nicholson, "they became unavailable to us because it very difficult to nail down a big star."

There was also the question of finding someone who could play Mandela from young man to elder statesman. In the end, the answer was found not in Hollywood but in an actor from Hackney, London.

Chadwick had gone to New York to see Elba, who was working there at the time. His verdict: call off the search. Nicholson remained unsure, only because there was little physical resemblance. One look at Elba in action dispelled any doubt.

"I was completely bowled over. He's an astonishing actor, he's delivered something amazing. I've written films that have been completely crucified by bad casting. You can ruin a movie with casting. This one has been made by this casting."

Since Elba was required to age several decades, he spent many an hour in the make-up chair. As he did so, The Wire and Luther star watched tape after tape of Mandela. Even though the immersed himself in the role, this was not, says Nicholson, an exercise in method acting.

"He's not like one of these people who goes into character like Daniel Day-Lewis for the whole film, not a bit of it. He's straight out and then straight back in again."

The other piece of casting it was crucial to get right was Winnie Mandela. Although the filmmakers had extended their search to include South Africans, it was a British actress, Naomie Harris, who won the part.

By the time the film was finished, Mandela was too ill to view it. Eventually, one of Mandela's daughters, Zindzi, got to see the film, together with his wife, Graca Machel, and Winnie. At the premiere, Zindzi called Elba's performance "brilliant" and said the filmmakers had done "an impeccable job".

He was particularly surprised at Winnie's support.

"It amazed me that Winnie embraced it, but I think the reason is there have been a lot of films about Winnie and they are all terrible. I think she saw this and thought thank God somebody is attempting to understand why I became what I became."

Mandela himself had given his blessing to the film's producer, Anant Singh, to turn the book into a film, but there was never any pressure to make this an "authorised" version of Mandela's life, says Nicholson. "There is nothing that I was told not to put in. Nobody at any point said don't put this in. "

Indeed, he says, he has gone further than previous films. "For example, a lot of people are astounded to hear that he liked women, cars and suits, things like that. From the beginning the intention has been to tell the truth but it is a drama, it is not a 20-part documentary."

Even as he accepts that, Nicholson still mourns the fact that, as with any life story, so much had to be condensed, particularly when it came to the politics of the ANC and the negotiations before the election.

"All of this was argued at enormous length by an enormous number of people. I had to just cut straight through all of that."

He hopes that the film will be seen by young and not so young alike, though he knows it will be more of a battle to convince the former they should choose this over, say, a comic book movie.

"The industry thinks it exists to entertain teenagers. The hell with that. There are a lot of grown-ups out there, a lot of mature people, and I'm hoping they will mob the cinemas."

Whatever the make-up of the audience, Nicholson believes the lesson of Mandela's life will prove universal.

"My job was to get across to an audience why this man was able to do what he did. What actually happened, what was the moral quality that in the end changed that society, and in changing that society proves to the rest of us that it can happen anywhere else?"

Mandela: Long Walk to Freedom, opens tomorrow