In beginning to write novels, it was Gaskell's hope that they would provide some solace from the pain of the loss of her son Willie. The idea, according to her early biographer Ellis Chadwick, was first suggested by her husband William Gaskell to 'sooth her sorrow'. In an 1849 letter to her friend Mrs Greg, Gaskell said that she, 'took refuge in the invention to exclude the memory of painful scenes which would force themselves upon my remembrance.'
However, it is clear from her preface that the suffering she saw around her was the motivational factor for the content of the novel: 'I had always felt a deep sympathy with the care-worn men, who looked as if doomed to struggle through their lives in strange alternations between work and want[...] The more I reflected on this unhappy state of things between those so bound to each other by common interests, as the employers and the employed must ever be, the more anxious I became to give some utterance to the agony which from time to time convulsed this dumb people.'
Gaskell's desire to accurately represent the poverty of industrial Manchester is evident in a record of a visit she made to the home of a local labourer. On comforting the family, Hompes records, the 'head of the family took hold of her arm and grasping it tightly, said, with tears in his eyes: "Aye, ma'am, but have ye ever seen a child clemmed to death?"' This question is almost precisely repeated in the mouth of John Barton: 'Han they ever seen a child o' their'n die for want o' food?' in chapter 4.
As well as relying on her own experience, Gaskell is thought to have used secondary sources on which to base the setting of the story, including Kay's The moral and physical condition of the working classes involved in the cotton manufacture in Manchester (1832) and Peter Gaskell's The manufacturing population of England (1833). Other details to which Gaskell paid particular attention to ensure the realism of the novel include the topography of both Manchester and Liverpool (including the rural environment detailed in the first chapter, and references to road names and prominent buildings), the superstitions and customs of the local people and the dialect. In the earliest editions, William Gaskell added the footnotes explaining some of the words specific to the Lancashire dialect, and after the fifth edition (1854), two lectures of his on the subject were added as appendices. It is widely thought that the murder of Harry Carson in the novel was inspired by the assassination of Thomas Ashton, a Manchester mill-owner, in 1831.
Mary Barton was first published as two volumes in October 1848.[Note 1] Gaskell was paid £100 for the novel. The publisher Edward Chapman had had the manuscript since the middle of 1847. He had several recorded influences on the novel, the most prominent of which is probably the change in title: the novel was originally entitled John Barton. Gaskell said that he was, 'the central figure to my mind...he was my "hero".' He also encouraged Gaskell to include chapters 36 and 37, the dialectical glosses added by William Gaskell, a preface and the chapter epigraphs.
The second edition, with Gaskell's corrections, particularly on typographical mistakes when writing the Lancashire dialect, appeared on 3 January 1849. The third edition soon followed, in February. A fourth, without Gaskell's involvement, appeared in October 1850. The fifth edition, from 1854, was the first single volume edition and included WIlliam Gaskell's lectures on dialect.