Revelation of the Qur'an

The Qur'an was sent down by Allah (swt) to Prophet Muhammad (saw) through revelation in order for Him to convey it to people. Revelation is the secret and rapid transmission of information to Allah's (swt) servant chosen from among people. This transmission may be directly to the prophet or through Jibrail (Gabriel). It is impossible for us to fully understand the nature of revelation with our human perceptions.
The first verses of the Qur'an were revealed on the 27th night of Ramadan in 610, when the Prophet Muhammad (saw) was forty years old. (Baqarah, 2/185; Dukhan, 44/1-3; Qadr, 97/1) When Muhammad (saw) approached the age of forty, He began to go to Hira Cave to be alone and contemplate. After a while, the following verses of Surah Alaq were revealed to Him in the Hira Cave: “Recite in the name of your Lord who created - Created man from a clinging substance. Recite! and your Lord is the most Generous - Who taught by the pen - Taught man that which he knew not.” (Alaq, 96/1-5) This and the information is given to him thereafter meant that he was tasked with prophethood. 
Prophet Muhammad's (saw) visits to Hira Cave does not mean that He was expecting prophethood. Because He experienced fear and anxiety when the angel of revelation came. The Qur'an explains that He had no such expectation: “And you were not expecting that the Book would be conveyed to you, but [it is] a mercy from your Lord.” (Qasas, 28/86)
The Qur'an was not revealed at once, but piece by piece over a period of 23 years. (Furqan, 25/32) This is unique to the Qur'an, unlike other books. There are various reasons for the Qur'an to be revealed piece by piece: better understanding and adoption of the revelation, giving time to those who have difficulties in understanding or applying it, transforming the society in parallel with the flow of life, keeping the interest in the revelation alive, etc. 

19