The product of a year and a half of writing, the book draws on Melville's experience at sea, on his reading in whaling literature, and on literary inspirations such as Shakespeare and the Bible. The white whale is modeled on the notoriously hard to catch actual albino whale Mocha Dick, and the ending is based on the sinking of the whaler Essex by a whale. The detailed and realistic descriptions of whale hunting and of extracting whale oil, as well as life aboard ship among a culturally diverse crew, are mixed with exploration of class and social status, good and evil, and the existence of God. In addition to narrative prose, Melville uses styles and literary devices ranging from songs, poetry, and catalogs to Shakespearean stage directions, soliloquies, and asides.
Dedicated to Nathaniel Hawthorne, "in token of my admiration for his genius", the work was first published as The Whale in London in October 1851, and under its definitive title in New York in November. Hundreds of differences, mostly slight and some important, are seen between the two editions. The London publisher censored or changed sensitive passages and Melville made revisions, as well, including the last-minute change in the title for the New York edition. The whale, however, appears in both editions as "Moby Dick", with no hyphen. About 3,200 copies were sold during the author's life.