A Doll's House was based on the life of Laura Kieler (maiden name Laura Smith Petersen), a good friend of Ibsen. Much that happened between Nora and Torvald happened to Laura and her husband, Victor. Similar to the events in the play, Laura signed an illegal loan to save her husband. She wanted the money to find a cure for her husband's tuberculosis. She wrote to Ibsen, asking for his recommendation of her work to his publisher, thinking that the sales of her book would repay her debt. At his refusal, she forged a check for the money. At this point she was found out. In real life, when Victor discovered about Laura's secret loan, he divorced her and had her committed to an asylum. Two years later, she returned to her husband and children at his urging, and she went on to become a well-known Danish author, living to the age of 83.
Ibsen wrote A Doll's House at the point when Laura Kieler had been committed to the asylum, and the fate of this friend of the family shook him deeply, perhaps also because Laura had asked him to intervene at a crucial point in the scandal, which he did not feel able or willing to do. Instead, he turned this life situation into an aesthetically shaped, successful drama. In the play, Nora leaves Torvald with head held high, though facing an uncertain future given the limitations single women faced in the society of the time.
Kieler eventually rebounded from the shame of the scandal and had her own successful writing career while remaining discontented with sole recognition as "Ibsen's Nora" years afterwards.
Ibsen started thinking about the play around May 1878, although he did not begin its first draft until a year later, having reflected on the themes and characters in the intervening period (he visualised its protagonist, Nora, for instance, as having approached him one day wearing "a blue woollen dress"). He outlined his conception of the play as a "modern tragedy" in a note written in Rome on 19 October 1878. "A woman cannot be herself in modern society," he argues, since it is "an exclusively male society, with laws made by men and with prosecutors and judges who assess feminine conduct from a masculine standpoint."
Ibsen sent a fair copy of the completed play to his publisher on 15 September 1879. It was first published in Copenhagen on 4 December 1879, in an edition of 8,000 copies that sold out within a month; a second edition of 3,000 copies followed on 4 January 1880, and a third edition of 2,500 was issued on 8 March.