In 1990, Rowling was on a crowded train from Manchester to London when the idea for Harry simply “fell” into her head. Rowling gives an account of the experience on her website:

I had been writing almost continuously since the age of six but I had never been so excited about an idea before. To my immense frustration, I didn't have a functioning pen with me, and I was too shy to ask anybody if I could borrow one. I think, now, that this was probably a good thing, because I simply sat and thought, for four (delayed train) hours, and all the details bubbled up in my brain, and this scrawny, black-haired, bespectacled boy who didn't know he was a wizard became more and more real to me. I think that perhaps if I had had to slow down the ideas so that I could capture them on paper I might have stifled some of them (although sometimes I do wonder, idly, how much of what I imagined on that journey I had forgotten by the time I actually got my hands on a pen). [1]
That evening J.K. Rowling began the pre-writing for her first novel, Harry Potter and the Philosopher's Stone (Sorcerer's Stone in the U.S.), pre-writing that would include the plot to each of her seven planned books, in addition to an enormous amount of historical and biographical information on her characters and universe. [2] Eventually Rowling relocated to Portugal, where she in 1992 married her first husband, and in 1993 had her first child, Jessica, all the while continuing her writing of Stone. When the marriage dissolved, Rowling returned to Britain with her daughter and settled in Edinburgh to be near her sister, famously continuing her writing of Philosopher's Stone in local coffee shops. Bringing in only £90 a week (£70 of which were from income support) and unable to secure a place for her daughter in a nursery, the sleeping infant Jessica would be a constant companion to her mother as Rowling labored to finish the book that she had at this point begun to fear would never be completed.