WHEN discussing spy fiction with Dame Stella Rimington it is sometimes easy to forget who is on the other end of the telephone line.

The lady with the well formed views on le Carre, Buchan and Bond - all to be revealed in a lecture at Edinburgh University this Friday - laughs easily, keen to share.

Only when she refers to such matters as "being tapped on the shoulder", or the mysterious "they" who look at her novels before publication, is one reminded that she was the first female head of MI5, the real-life "M" of the Bond films.

Dame Stella, 78, will be visiting Edinburgh to take part in "Spy Week", a series of events running until April 12. Her contribution is a lecture, Espionage in Fact and Fiction; her cv, and her reinvention as the writer of the bestselling Liz Carlyle spy novels, qualifies her to speak on both counts.

"I suppose it's just the mystery of the whole thing," the mother and grandmother says when asked to explain spy fiction's enduring appeal. "That nobody really knows what is fact and what is fiction."

She was a fan before she joined the service. Indeed, the then-diplomat's wife had just finished Kim, "all about The Great Game, the eternal battle between Britain and Russia fought out on the North West Frontier" when she was approached to join.

A common error in spy fiction, she says, is getting the balance between action and analysis wrong. Too much of the former and it is more of an adventure story than an accurate reflection of how intelligence works.

That is one of the reasons why she regards John le Carre as a master.

"Smiley is a thoughtful kind of character, and he takes action only after he has analysed the situation. That's a much more realistic approach than some of the more gung-ho heroes you find in other books."

The work is not only about analysis though, she agrees. "One of the most important parts of intelligence work is acquiring the intelligence, and often that comes from human sources who are often in difficult and dangerous situations."

While not much of a moviegoer, she was entranced by the 2011 film version of Tinker, Tailor, Soldier Spy, which transported her back to the "gloom and greyness" of the early 1970s when she joined MI5. Light and colours crop up again when Dame Stella talks about returning to her alma mater of Edinburgh, where she studied English in the 1950s.

"We lived in a tenement which is now no longer there, near Arthur's Seat, called Prince Albert Buildings. That was a jolly gloomy place to live, but that was all part of the romance. I went to Edinburgh in the first place because of a romantic feeling about the Celtic twilight and suchlike. I was quite young in those days," she laughs.

After leaving the service in 1996 she wrote her autobiography, Open Secret, an act of openness in keeping with being the first head of MI5 to be publicly named. Seven novels have followed. Was MI5 relaxed about the novels?

"They were certainly a lot more relaxed about the novels than they had been about my autobiography. I still have to submit my books for clearance. The rules are that anybody who writes anything that can be seen to connect to their work has to have it cleared, so every time I write a book I send it in for clearance, which is all good. It's good for me and good for them to be sure that I'm not inadvertently giving away something that relates to what they are currently doing."

There is a little bit of Liz Carlyle in her, she says, albeit Liz has more freedom. "You have to remember when I joined the service women were definitely second class citizens, we were not allowed to do any of the things that Liz Carlyle does. We were desk bound, our job was to look after the papers, support the blokes. Liz, being an active, up-front person is a reflection of some of the things I thought at the beginning but wasn't able to say."

She once called Fleming's Bond "an anachronistic old duffer", but she enjoyed the last film, Skyfall. As for Dame Judi Dench's "M", she can do no wrong; which might have a lot to do with the resemblance between the real M and the fictional one. When Rimington's daughters went to see the first Bond featuring Dench they reported back that the screen M was just like mum.

"That was flattering," says Rimington. Spy fact and fiction together at last.

April 11, 5:30pm-7pm, The Playfair Library Hall, Old College, South Bridge, Edinburgh. www.spyweek.llc.ed.ac.uk