Allah tells us how perfect is His knowledge of His creation, and that He encompasses all that is in the heavens and on earth

Not even the weight of a speck of dust, or less than that or greater escapes His knowledge in the heavens or in the earth. He knows all things even before they happen, and He has written that in His Book, Al-Lawh Al-Mahfuz, as was reported in Sahih Muslim from `Abdullah bin `Amr, who said, "The Messenger of Allah ﷺ said:

«إِنَّ اللهَ قَدَّرَ مَقَادِيرَ الْخَلَائِقِ قَبْلَ خَلْقِ السَّموَاتِ وَالْأَرْضِ بِخَمْسِينَ أَلْفَ سَنَةٍ، وَكَانَ عَرْشُهُ عَلَى الْمَاء»

(Allah issued His decrees concerning the measurement and due proportion of the creatures fifty thousand years before He created the heavens and the earth, and His Throne was over the water.) In the Sunan, it was reported from a group of the Companions that the Messenger of Allah ﷺ said:

«أَوَّلُ مَا خَلَقَ اللهُ الْقَلَمُ، قَالَ لَهُ: اكْتُبْ، قَالَ: وَ مَا أَكْتُبُ؟ قَالَ: اكْتُبْ مَا هُوَ كَائِنٌ، فَجَرَى الْقَلَمُ بِمَا هُوَ كَائِنٌ إِلَى يَوْمِ الْقِيَامَة»

(The first thing that Allah created was the Pen. He said to it, "Write!" It said, "What should I write" He said, "Write what will happen," so the Pen wrote everything that will happen until the Day of Resurrection.) Allah says:

إِنَّ ذلِكَ فِى كِتَـبٍ إِنَّ ذلِكَ عَلَى اللَّهِ يَسِيرٌ

(Verily, it is (all) in the Book. Verily, that is easy for Allah.)