Question: What does ghayb mean? Who knows the ghayb?
Ghayb are those things that cannot be known through sense organs, calculations, or experiments. Only Allahu ta’âlâ knows the ghayb.

He is ‘Âlim-ul-ghayb [the Knower of the ghayb] (Sûrat-ul-Hashr, 22) and ‘Allâmul ghuyûb [the One who knows the ghaybs best] (Sûrat-u Saba’, 48).

The purport of some pertinent âyât is as follows:
(Do they still not understand that Allah is the best Knower of the ghaybs?) [Sûrat-ut-Tawba, 78]

(Say: “The knowledge of the ghayb belongs to Allah.”) [Sûrat-u Yûnus, 20]

(To Allah belongs the ghayb of the heavens and the earth.) [Sûrat-u Hûd, 123; Sûrat-un-Nahl, 77]

(Say: “No one in the heavens and on earth knows the ghayb except Allah.”) [Sûrat-un-Naml, 65; Sûrat-ul-Hujurât, 18]

Even prophets cannot know the ghayb. As a matter of fact, some pertinent âyât are as follows:
(Nor do I know the ghayb.) [Sûrat-ul-An‘âm 50; Sûrat-u Hûd, 31]

(With Allah are the keys to the ghayb.) [Sûrat-ul-An‘âm, 59]

(Say: “If I knew the ghayb, I would certainly wish to do far more good works.”) [Sûrat-ul-A’râf, 188]

Genies cannot know the ghayb, either. The purport of an âyah is as follows:
(If genies had known the ghayb, they would not have remained in disgracing torment.) [Sûrat-u Saba’, 14]

It is kufr [disbelief] to say, “Such and such a hodja or such and such a fortune teller knows the ghayb.” It is stated in a hadîth-i sharîf:
(He who believes the prophecies of a fortune teller, a sorcerer, or anyone has not believed in the Qur’ân al-karîm.) [Tabarânî]

If Allahu ta’âlâ wills, He lets His prophets know some matters from the ghayb. Two related âyât purport:

(Allah does not let you know the ghayb, but He discloses it to whomever He wishes from among His prophets.) [Sûrat-u Âl-i ‘Imrân, 179]

(Allah does not disclose the ghayb to anyone, except to a prophet He wishes. For He dispatches observers before and behind each prophet.) [Sûrat-ul-Jinn:26, 27]

It is revealed in the Qur’ân al-karîm that Hadrat Mûsâ said to a man who has ‘ilm-i ladun (that is, to whom Allah disclosed the ghaybs): “I want to follow you so that you, too, teach me the knowledge which our Rabb has taught you and which will help me find the truth and will lead me to goodness” (Sûrat-ul-Kahf, 66).

We were notified that this man who knew the ghayb and who had ‘ilm-i ladun was Hadrat Khidr. In the same way, many matters pertaining to the ghayb were disclosed to our master Rasûlullah. Some ahâdîth declare:
(Close the gaps in between your lines, for surely I can see you from behind my back.) [Muslim]

(Perform rukûs and sajdas properly. I swear by Allah that I can see your performing rukû’ and sajda from behind my back.) [Bukhârî, Muslim]

Allahu ta’âlâ, who has bestowed upon the eyes the ability to see, has the capability to create sight in other body organs as well. Those who negate this miracle of Rasûlullah’s has negated the omnipotence of Allahu ta’âlâ. That Rasûlullah used to see both in the daytime and in the dark is reported in a hadîth-i sharîf written in Bukhârî.

Yes, the fact is that no one other than Allah knows the ghayb. If it is said that one can know, it causes disbelief. One day, the camel of our master Rasûlullah got lost. Then the hypocrites drew advantage from that situation and scoffed, “He has been talking about Paradise and Hell, but he does not know even the place of his camel.”

When our master Rasûlullah heard about these words, he stated, “I swear by Allah that I can only know what my Rabb has communicated to me. Now my Rabb has told me the whereabouts of my camel. My camel is now at such and such a place.” They went to the place described and found the camel in a state tethered to a tree. (Mawâhib-i ladunniyya)

However, if Allahu ta’âlâ makes it accessible, His Messenger or His awliyâ can know the ghayb. We have listed its proofs above exhaustively. A hadîth-i sharîf relates:

(If your hearts were pure, you, too, would hear what I hear.) [I. Ahmad, Tabarânî] (As a matter of fact, Hadrat ‘Umar, whose heart was pure as this hadîth-i sharîf declares, saw in Medina his army warring in Iran and called out the commander-in-chief of the army, Sâriya, “Sidle up towards the mountain.” (Shawâhid-un-Nubuwwa)

Again a hadîth-i sharîf declares:
(In the past Ummats there were people of karâmah who foretold some events pertaining to the ghayb before they took place. Of my Ummat, ‘Umar is one of those.) [Bukhârî, Muslim]

Like Hadrat ‘Umar, other awliyâ’, too, performed many karâmat. The Qur’ân al-karîm confirms this fact: (Sûrat-un-Naml, 38-40; Sûrat-u Maryam, 24; Sûrat-u Âl-i ‘Imrân, 37; Sûrat-ul-Kahf:17, 18)

Conclusion: Allahu ta’âlâ makes the ghayb known to whomever He wishes, and this person in turn brings news from the ghayb. (Awârif-ul-ma’ârif)

Is it possible to know the ghayb?
It is stated in the Qur’ân that the gender of a baby in the womb and when it rains cannot be known (that is, the ghayb cannot be known). However, a baby’s gender can be determined by means of ultrasound scan. Weather forecasts can be carried out through certain techniques. Therefore, is it possible to clear this âyah up?
The purport of that âyah is as follows:
(Only Allah knows when the Doomsday (end of the world) will take place. It is He who knows [where, when, and how much] rain He will send and what is in the wombs, too. No one can know what he will earn [from good and evil] tomorrow and where he will die. Surely Allah is All-knowing and is aware of everything.) [Sûrat-u Luqman, 34]

Mansur saw the Angel of Death in his dream and asked him how long he would live. The angel showed his five fingers in response. Some dream interpreters construed it as five years, some as five months, and some others as five days. Hadrat Imâm-i A’zam Abû Hanifa, on the other hand, interpreted, The Angel of Death meant to say, ‘I do not know it. It is one of the five ghaybs stated in the Luqman Sûra.’” (Madârik)

What does ghayb mean? If the meaning of it is known well, the answer to your question can be understood quite easily. Ghayb are those things that cannot be known through sense organs, calculations, or experiments. For example, the existence of Jannat, Jahannam, and angels is included in this category. That when a child grows up, or such things, whether he or she will become a good person or an evil person, a scholar or a cruel one cannot be told in advance through modern techniques.

Today as we can find out the sex of a baby via ultrasound or other methods, it is not considered something ghayb, but something empirical. The statement “Only Allah knows what is in the wombs” does not point out only the gender of an unborn baby. Rather, it means, “Only Allah knows such matters as whether a baby will be born safe and sound, whether it will go to Paradise or Hell, and what deeds it will do.” Even today gender identification can be achieved after a certain number of weeks. If a fetus is younger than three months of age, its gender cannot be identified. But it is natural to detect the gender after its organs have taken shape. Then it can be learned via a device, so it is not ghayb. Or when the abdomen of a woman is cleft through a surgical operation, it will not be ghayb to see the gender of the baby at that moment. Again it will not be to claim knowledge of the ghayb to detect its gender by means of a device or ultrasound scan without ever cleaving her abdomen. Similarly, it is not considered to reveal the ghayb to observe the weather through certain techniques, to forecast rain, and to publicize it. Likewise, it is not regarded as revealing the ghayb to see out of the window a man approaching home and to say, “Someone is coming.” What is considered to claim knowledge of the ghayb is to know without seeing.

Allahu ta’âlâ makes known the ghayb to whomever He wishes through mu’jiza and karâmah. Their knowing is not contrary to the verse “Only Allah knows,” because the purport of the verse “Only Allah knows” is “No one can know it unless He makes known.”

Knowing the thoughts in the hearts
Is there such an âyah that “only Allah knows what is in the hearts”?
Yes, there are many. The purport of some is as follows:
(I created man and know what his nafs whispers to him [what he thinks], and I am closer to him than his jugular vein.) [Sûrat-u Qaf, 16]

(Allah knows whatever their hearts conceal or reveal.) [Sûrat-un-Naml, 74]

(Surely, Allah fully knows what is in the hearts.)
[Sûrat-u Âl-i ‘Imrân, 119]

(Allahu ta’âlâ knows all that is in your hearts.) [Sûrat-u Âl-i ‘Imrân, 154]

(They were saying with their mouths what was not in their hearts. But Allah certainly knows what they conceal in their hearts.) [Sûrat-u Âl-i ‘Imrân, 167]

(Allah knows what is in their hearts.) [Sûrat-un-Nisâ’, 63]

(Allah knows what is in the hearts.) [Sûrat-ul-Anfal, 43; Sûrat-uz-Zumar, 7; Sûrat-ut-Taghâbun, 4]

(Allah is the Knower of what is in the hearts.) [Sûrat-u Hûd, 5]

(Whether you hide your utterances or state them openly, He knows what is in the hearts. Does the One, who created, not know?) [Sûrat-ul-Mulk:13,14]

Only Allahu ta’âlâ is the Knower of the thoughts, the inmost secrets within the hearts. Besides, His beloved slaves and His prophets can know as much as Allah lets them know.