Darkness at Noon is an allegory set in the USSR (not named) during the 1938 purges as Stalin consolidated his dictatorship by eliminating potential rivals within the Communist Party: the military and the professionals. None of this is identified explicitly in the book. Most of the novel occurs within an unnamed prison and in the recollections of the main character, Rubashov.
Koestler drew on the experience of being imprisoned by Francisco Franco's officials during the Spanish Civil War, which he described in his memoir, Dialogue with Death. He was kept in solitary confinement and expected to be executed. He was permitted to walk in the courtyard in the company of other prisoners. Though he was not beaten, he believed that other prisoners were.