"Most scholars agreed that the Nights was a composite work and that the earliest tales in it came from India and Persia. At some time, probably in the early 8th century, these tales were translated into Arabic under the title Alf Layla, or 'The Thousand Nights'. This collection then formed the basis of The Thousand and One Nights. The original core of stories was quite small. Then, in Iraq in the 9th or 10th century, this original core had Arab stories added to it—among them some tales about the Caliph Harun al-Rashid. Also, perhaps from the 10th century onwards, previously independent sagas and story cycles were added to the compilation [...] Then, from the 13th century onwards, a further layer of stories was added in Syria and Egypt, many of these showing a preoccupation with sex, magic or low life. In the early modern period yet more stories were added to the Egyptian collections so as to swell the bulk of the text sufficiently to bring its length up to the full 1,001 nights of storytelling promised by the book's title."
Irwin, Robert (2003), The Arabian Nights: A Companion
(Source: Wikipedia)