After 22 years of imprisonment on Robben Island, South Africa's penal colony six miles off Cape Town, Nelson Mandela was transferred to Pollsmoor Prison on the mainland. Not long after, in May 1984, he was visited by his wife Winnie. Before being taken to a waiting room, she was led to the office of the warden.

''I was petrified,'' Mrs. Mandela recalled. ''I thought Nelson must be very ill, and the commanding officer was going to break it to me gently. So you can imagine the shock and tremendous relief and euphoria when he told me I was to be allowed a contact visit. ''The couple had not touched each other for 22 years. ''We just clung to each other,'' Mrs. Mandela wrote. ''We were stunned and thrilled at the same time.''

The poignant story, one of hundreds from the prison years of Nelson Mandela, is temporarily submerged by the applause and embraces he is receiving in his tour of North America. Whatever political successes he may win for South Africa, Mandela joins a long list of modern-age political prisoners whose jailings strengthened their defiance of the state.

Mandela has yet to go from the jail cell to the writer's cell. But if he does, the account will be part of the 20th century's most gripping autobiography: prison memoirs. A sampling of only a dozen of the acclaimed books suggests the breadth: ''Prisoner Without a Name, Cell Without a Number,'' Jacobo Timerman; ''Prison Writings,'' Kim Dae Jung; ''Gulag Archipelago,'' Alexander Solzhenitsyn; ''Against All Hope: the Prison Memoirs of Armando Valladares''; ''Psalms from Prison,'' Benjamin Chavis; ''Prisons That Could Not Hold,'' Barbara Deming; ''Prison Memoirs of an Anarchist,'' Alexander Berkman; ''The Prison Diaries of Ho Chi-Minh''; ''Fourteen Poems,'' Natalya Gorbanevskaya; ''Journey Into the Whirlwind,'' Eugenia Ginzburg; ''Letters and Papers from Prison,'' Dietrich Bonhoeffer; ''Prison Poems,'' by Daniel Berrigan.

Also in the literature are the essays and texts that are part of the collected writings of other unconquered inmates: from Martin Luther King's ''Letter From a Birmingham Jail'' to the letters from a Berlin women's prison by Rosa Luxemburg and from a West Virginia prison by Mother Jones.

The theme of cellblock literature is that the iron of the prisoner's will is stronger than the steel of the state's bars. What Nelson Mandela said in 1978 from Robben Island, ''What freedom am I being offered while the organization of the people remains banned?'' echoed the thought in 1920 of Eugene V. Debs, Convict 9653 in the Atlanta federal penitentiary: ''While there is a soul in prison, I am not free.''

That is probably the most remembered line of Debs, five times the Socialist candidate for president. It is seen now as sentimentalism, in a day when too many politicians are guided by polls, not passions, and are jailed for corruption, not conscience. In ''Walls and Bars,'' Debs describes the liberation of confinement, a statement of fact more than sentimentality: ''I was never more free in my life, so far as my spirit was concerned, than I was in that prison cell.''

Wit turns up in prison memoirs. During World War II, when one in six federal prisoners was a conscientious objector, Lowell Naeve, a pacifist, was doing time in the Danbury, Conn., federal prison. When he met fellow inmate Louis Lepke, the hoodlum boss of ''Murder Inc.,'' the convicted murderer could not see conscientious objection to war as a crime: ''You mean they put you in here for not killing?"

Political prisoners write of surviving by means of attachments to causes beyond the walls and by drawing on inner reserves. Benazir Bhutto, the elected prime minister of Pakistan, wrote of enduring her imprisonment in 1981: ''I started to pray a special prayer for my release that one of the jail matrons told me about: 'Qul Huwwa Allahu Ahad, Say He Is One God.' I started the 112th sura of the Quran, reciting the verses 41 times, then breathing over a mug of water and sprinkling a little of the water in each of the four corners of the cell. I prayed for every prisoner. I prayed for my mother. I prayed for myself.''

Vaclav Havel, another ex-prisoner now running a government, recalls that while in prison ''I thought constantly about what I would eventually write about, and how. I tried to remember all those curious yet moving, comic yet shocking, strange yet typical experiences I had there.'' On release, he decided not to write: ''It was a deeply existential and deeply personal experience, and as such I'm simply unable to pass it on.''

It may be that way for Nelson Mandela. How can 27 years be stunted into a book? His reception in North America suggests that sometimes a hero comes along who doesn't need to tell of the heroic. The public feels it by seeing him walking free.