Appropriately enough for a gothic novel, The Little Stranger was born out of a nightmare. During a stay at the literary festival at Dartington Hall a few years ago, I woke with a shriek in the middle of the night, imagining I'd seen a spectral figure standing at the foot of the bed. It was nothing to do with the (gorgeous) location; I'd been plagued by the same bad dream for months. But thinking back to that moment on a subsequent visit to the festival, in July 2006, I found myself musing on ghosts – and started to wonder whether a spot of the supernatural mightn't be just the thing to perk up my barely begun new novel.

The novel was to be set in the 1940s, and was to have as its background changes in the British class system. It had been inspired by the deep anxiety I'd seen at work in the fiction of conservative 40s writers such as Angela Thirkell and Josephine Tey – an anxiety about a changing social system and a newly confident working class that amounted, at times, to a kind of hysteria. In looking for a way to address the issue, I had been thinking of attempting a rewrite of Tey's fascinating but deeply troubling novel of 1948, The Franchise Affair. Now, lying in the darkness at Dartington Hall, it struck me that I could take the class tensions underpinning conservative postwar paranoia and rewrite them as something actively paranormal. I suppose I was thinking, in effect: "I'll give those snobs something really to get hysterical about!"

From the start, I knew that a poltergeist would serve me better than a simple ghost. I've always been drawn to the post-Freudian interpretation of the poltergeist as an acting-out of psychic distress – "a bundle of projected repressions", as Hereward Carrington and Nandor Fodor put it in their 1951 study of the phenomenon, Haunted People. In other words, while Hundreds Hall, my fictional setting for the novel, was definitely to be a haunted house, it was to be haunted not by the spirits of the dead, but by the unconscious aggressions and frustrations of the living. I wanted The Little Stranger to be a sort of supernatural country house whodunit – a "whose poltergeist is it?" – in which the Hall's hapless inhabitants would get picked off one by one, and every character – the grieving mother, the war-scarred son, the spinster daughter, the lonely servant, the whole changing nation around them – would have more than enough unconscious conflicts to constitute a possible "suspect".

The novel's narrator, Dr Faraday, I at first planned to be a rather transparent figure in the classic ghost-story style of MR James or Oliver Onions: I saw him as a middle-class friend of the family, the baffled, impotent chronicler of its decline. Then it occurred to me to try complicating his background. I turned him into a working-class boy made good, a man cut off from his modest roots yet not quite at ease as a middle-class professional; a man drawn to the glamour of Hundreds even while bearing an atavistic resentment towards it. At once, his transparency began to cloud, and soon his very opaqueness appealed to me: I saw in it wonderful possibilities of unreliability, something I had never explored with a narrator before. That led to the main technical challenge in what was an otherwise pretty straightforward writing process: how to maintain Dr Faraday's bland narrative surface, while finding ways to suggest that there was a whole layer of sometimes turbulent activity going on just beneath it.

Almost as soon as the book was published it became obvious to me that, for some readers, this was a challenge I had not met. Since then, I have grown used to hearing Dr Faraday abused as dull, annoying, frustrating. I also receive a steady stream of emails asking me to "explain" the novel's ending, to settle a dispute between friends, or between the members of a book group, about who or what it is that Caroline recognises when she calls out "You!" in the moments before her death. My usual response is to say that I deliberately left the resolution open; that I wanted to do justice to the essential strangeness of the supernatural; that I am very happy for readers to make up their own minds. All this is true – sort of. The fact is, I worked hard to spike the novel with clues as to where, exactly, the "bundle of projected repressions" which consumes Hundreds Hall has its roots; the spikiest of these is the book's last line. When these clues do snag their reader, I experience a glow of writerly satisfaction and feel I pitched things just right. When they don't – well, The Little Stranger is about conflict and waste; I never wanted its effect to be tidy. No other novel of mine has inspired such a range of responses in its audience, and that's been a fascinating experience.