Bismillahir Rahmanir Rahim.
Hadith
718. Jabir (May Allah be pleased with him) reported: Messenger of Allah (sal Allahu alaihi wa sallam)) used to teach us the Istikharah (seeking guidance from Allah) in all matters as he would teach us a Surah of the Qur'an. He used to say: "When one of you contemplates entering upon an enterprise, let him perform two Rak`ah of optional prayer other than Fard prayers and then supplicate: "Allahumma inni astakhiruka bi `ilmika, wa astaqdiruka bi qudratika, wa as-'aluka min fadlikal-`azim. Fainnaka taqdiru wa la aqdiru, wa ta`lamu wa la a`lamu, wa Anta `allamul-ghuyub. Allahumma in kunta ta`lamu anna hadhal-`amra (and name what you want to do) khairun li fi dini wa ma`ashi wa `aqibati amri, (or he said) `ajili amri ajilihi, faqdurhu li wa yassirhu li, thumma barik li fihi. Wa in kunta ta`lamu anna hadhal `amra (and name what you want to do) sharrun li fi dini wa ma`ashi wa `aqibati amri, (or he said) wa `ajili amri wa ajilihi, fasrifhu `anni, wasrifni `anhu, waqdur liyal-khaira haithu kana, thumma ardini bihi.'' (O Allah, I consult You through Your Knowledge, and I seek strength through Your Power, and ask of Your Great Bounty; for You are Capable whereas I am not and, You know and I do not, and You are the Knower of hidden things. O Allah, if You know that this matter (and name it) is good for me in respect of my Deen, my livelihood and the consequences of my affairs, (or he said), the sooner or the later of my affairs then ordain it for me, make it easy for me, and bless it for me. But if You know this matter (and name it) to be bad for my Deen, my livelihood or the consequences of my affairs, (or he said) the sooner or the later of my affairs then turn it away from me, and turn me away from it, and grant me power to do good whatever it may be, and cause me to be contented with it). And let the supplicant specify the object.''
[Al-Bukhari and Muslim]
Commentary: Literally Istikharah means seeking goodness from Allah through a particular prayer. This Hadith lays emphasis on it and displays its significance. We should, therefore, practice Istikharah regarding every important matter. However, it is imperative only in cases where one is ignorant of good and evil. Yet, with regard to obligatory and indisputable rules, practices of the Prophet (sal Allahu alaihi wa sallam) and commendable deeds, no Istikharah is allowed. Similarly, commands and prohibitions of the Shari`ah are categorical and nobody is allowed to seek further guidance by performing Istikharah prayer. Moreover, to set aside the example of the Prophet (sal Allahu alaihi wa sallam) of Istikharah, and to trust astrologers, palmists and soothsayers seeking the knowledge of future events is sheer ignorance and unpardonable error. The knowledge of the Unseen (or Ghaib) is the domain of Allah Alone and man is supposed to seek His Blessings. Only Allah is Omnipotent and humans must turn to Him to seek inspiration and strength, trusting everything to His Care.
Istikharah prayer can be offered at any time except in the forbidden hours for prayer because the performance of two Rak`ah is a prerequisite to it. Some people think that the right time for it is before going to bed. This is not true. This supplication (Du`a) can be offered even after performing the two Rak`ah of Istikharah prayer, or before Taslim (i.e., saying Assalamu `Alaikum to conclude the prayer) after Tashahhud or in the state of prostration. If somebody does not know this Du`a by heart, he can, after performing the prayer, read it from some prayerbook.