Andersonville Prison, Ga., August 17, 1864. Issuing rations, view from main gate.(Library of Congress)

It was only in their sleep, in their unconscious minds, that the prisoners of war were free, making an ethereal escape from their wretched reality.

Some dreamed of escape. Some dreamed of death. Some dreamed of survival.

Some dreamed of beef and oysters, buffets and banquets. Some dreamed of kissing their wives and sweethearts. Some dreamed their women were unfaithful. Some dreamed of giant lice. Many dreamed of home.

The conditions for captured fighters in the Civil War were brutal. Prisoners lived in deep squalor, starving. They were forced to bury fellow prisoners who died of starvation. They were either sick or surrounded by disease.

Armies from the north and the south were having a hard enough time feeding their own soldiers, so as the war dragged on and supplies ran low, POWs would hope for bits of cornbread flung at them by the guards.

But their dreams could take them far away from all this, according to Civil War historian and author Jonathan W. White, who collected about 400 dreams of soldiers and prisoners of war for a forthcoming book.

[Related: How Gandhi and Paul McCartney used dreams to solve problems and surface great ideas]

White is one of the few historians or psychologists to study the dreams of POWs. A Harvard psychologist has analyzed dreams of British officers held by the Germans in World War II, drawing from a collection of about 500 dreams that were recorded in the prison, preserved and only recently discovered.

White, in searching letters, diaries, memoirs and regimental histories, discovered the dream life of those who fought the war that abolished slavery and proved to the world that the American Democratic experiment could endure.

As disturbing as some of the soldiers’ dreams were — to wake up, frothing at the mouth from a dream of a giant plate of ham and eggs was a particularly cruel torment — White found that the dreams also provided some solace to the prisoners.

“Dreams, for many of them, played a comforting role,” said White, whose latest book, “Midnight in America: Darkness, Sleep and Dreams During the Civil War,” will be published by the University of North Carolina Press. “The most common dreams soldiers had were of home, hugging or kissing their wives, picking up their children,” he said.

One New York soldier held by the Confederate Army at Andersonville, Ga. — — known officially as Camp Sumter — recalled that “dreams of home and of home comforts, especially the favorite dishes that had been prepared by the hands of a doting mother, a pet sister or a loving wife, were of nightly and even daily occurrence.”

Andersonville was the largest and deadliest of the 150 military prisons that operated during the war, according to the National Park Service, which maintains the grounds as a national historic site. Of the 45,000 Union soldiers imprisoned there, an estimated 13,000 died. The camp was originally built for no more than 10,000 POWs, according to several historical accounts, but at one point, after prisoner exchanges were halted, the population soared to more than 32,000.

White, who examined the dreams of northern and southern combatants and captives, said he was struck by the intimacy the soldiers sustained with their families through letters. Many of them would be away for as long as four years, the war’s duration.

Sharing their dreams, some of them revealing intense insecurities about infidelity and other fears, fostered that intimacy, he said. And sometimes the soldiers would use the story of a dream to address these worries with their wives, with the dream serving as a kind of protection from the discomfort of vulnerability.

Confederates captured Congressman Alfred Ely of New York during the first Battle of Bull Run, in July 1861, White writes, and Ely spent six months as a POW in Richmond, VA. One night he dreamed that the Confederates released him and sent him home to Rochester. But a Confederate officer accompanied him on the trip and, upon meeting Ely’s wife, suggested that he should replace Ely as her husband.

“It occurred to me,” Ely wrote of the dream in his journal, that all the letters his wife wrote to him while he was in the prison camp, had “passed through his hands, as officer of the post, with privilege of reading them all, and the idea that it might be the means of my ruin so appealed to my…combativeness that I hurled him a volley of invectives, accompanying it with violent gesticulations of anger.”

White found that prisoners found psychic sustenance in sharing their dreams with each other.

An examination of the dreams of British prisoners of war held by the Germans showed that soldiers fighting wars almost a century apart dreamed of remarkably similar themes, particularly of the longing for food.

Many of the prisoners at Laufen, a converted castle, were captured early in the war and had exceptionally hopeful dreams, said Deirdre Barrett, the lead author of a recent analysis of the dreams. As early as 1940 — with the war’s end years away — these British officers, most of whom were captured in the Battle of France, had regular dreams that the war was over.

Most likely such optimistic missives from their brains reflected the far better conditions these soldiers endured, as compared to the Civil War soldiers and to the torture and mass murder of Jews unfolding in Nazi concentration camps simultaneously, Barrett said.

“The dreams and the conditions sounded much more like other prisons,” she said. “Lonely, sad places isolated from family and usual activities.”

The dreams, with food being a frequent theme as it was for the Civil War POWs, “were a great comfort and helped them endure an unhappy, isolated experience,” she said.

The discovery of these dreams is a story unto itself. One of the British officers, Major Kenneth Hopkins, was a graduate student in psychology before the war. After he enlisted and was taken prisoner, he conducted a survey of his fellow captives, asking them if they would participate in a study of dreams.

Hopkins persuaded 79 prisoners to record or tell him their dreams the morning after they had them. Hopkins meticulously transcribed them in his journals and planned to use the material for his doctoral degree at the University of Birmingham.

But he died of emphysema in 1942, two years after he started and three years before Allied Forces liberated the camp in 1945. The Allies found his journals and sent them to Hopkins’s dissertation advisor in Birmingham.

The dreams were preserved but idle, until Barrett learned they were being kept in a historical collection in London. Barrett, one of the world’s leading dream researchers, recruited students and jumped into the material. Among the dreamers in the sample were the “Laufen Six,” who famously escaped the prison. Most of them, according to Barrett, had positive escape dreams, as opposed to other dreams where soldiers dreamed of escapes gone awry with terrifying outcomes involving themselves or fellow prisoners.

“Myself and three others escaped from prison,” according to one of the Laufen Six, recounting a dream he had before he broke out. “We lay up all day near the Slav border and we were going to cross at night. As evening wore on, we got prepared and were lucky enough to get a car. Around midnight we got into the car.”

Want more inspiring news and ideas to improve your life? Sign up for the Saturday Inspired Life newsletter.

If you liked this story on Inspired Life, you may also enjoy:

Radio host about lonely 95-year-old caller: ‘We’ve all got a Bill in our lives.’

Mind over meal: Study reveals a weight loss strategy you may never have considered.

The surprising effect of yoga on inmates with children