The scholars unanimously agreed that Istikharah is Sunnah. The evidence that it is prescribed is the hadith narrated by al-Bukhari from Jabir (may Allah be pleased with him) who said:
“The Messenger of Allah (peace and blessings of Allah be upon him) used to teach his Companions to make Istikharah in all matters, just as he used to teach them surahs from the Quran. He said: ‘If any one of you is deliberating about a decision he has to make, then let him pray two rak`ahs of non-obligatory prayer, then say:
(1)
أَللَّهُمَّ إِنِّي أَسْتَخِيرُكَ بِعِلْمِكَ وَأَسْتَقْدِرُكَ بِقُدْرَتِكَ وَأَسْأَلُكَ مِنْ فَضْلِكَ الْعَظِيمِ
فَإِنَّكَ تَقْدِرُ وَلَا أَقْدِرُ وَتَعْلَمُ وَلَا أَعْلَمُ وَأَنْتَ عَلاَّمُ الْغُيُوبِ أَللَّهُمَّ إِنْ كُنْتَ
تَعْلَمُ أَنَّ هَذَا الْأَمْرَ خَيْرٌ لِي فِي دِينِي وَمَعَاشِي وَعَاقِبَةِ أَمْرِي فَاقْدِرْهُ لِي وَيَسِّرْهُ لِي ثُمَّ بَارِكْ لِي فِيهِ وَإِنْ كُنْتَ تَعْلَمُ أَنَّ هَذَا الْأَمْرَ شَرٌّ لِي فِي دِينِي وَمَعَاشِي وَعَاقِبَةِ أَمْرِي فَاصْرِفْهُ عَنِّي وَاصْرِفْنِي عَنْهُ وَاقْدِرْ لِيَ الْخَيْرَ حَيْثُ كَانَ ثُمَّ أَرْضِنِي بِهِ* (قَالَ وَيُسَمِّى حَاجَتَهُ.
(1)
Allahumma inni astakheeruka bi ‘ilmika wa astaqdiruka bi qudratika wa asaluka min fadlika, fa innaka taqdiru wa la aqdir, wa ta’lamu wa la a’lam, wa anta ‘allam al-ghuyoob. Allahumma fa in kunta ta'lamu hadhal-amra (then the matter should be mentioned by name) khayran li fi ‘ajil amri wa ajilihi (or: fi deeni wa ma’ashi wa ‘aqibati amri) faqdurhu li wa yassirhu li thumma barik li fihi. Allahumma wa in kunta ta'lamu annahu sharrun li fi deeni wa ma’ashi wa ‘aqibati amri (or: fi ‘ajili amri wa ajilihi) fasrifni ‘anhu [wasrifhu ‘anni] waqdur li al-khayr haythu kana thumma raddini bihi
O Allah, I seek Your guidance [in making a choice] by virtue of Your knowledge, and I seek ability by virtue of Your power, and I ask You of Your great bounty. You have power, I have none. And You know, I know not. You are the Knower of hidden things. O Allah, if in Your knowledge, this matter (then it should be mentioned by name) is good for me both in this world and in the Hereafter (or: in my religion, my livelihood and my affairs ), then ordain it for me, make it easy for me, and bless it for me. And if in Your knowledge it is bad for me and for my religion, my livelihood and my affairs (or: for me both in this world and the next), then turn me away from it, [and turn it away from me], and ordain for me the good wherever it may be and make me pleased with it.
Reported by al-Bukhari, 6841; similar reports are also recorded by al-Tirmidhi, al-Nasai, Abu Dawood, Ibn Majah and Ahmad
(2)
اللَّهُمَّ إِنْ كُنْتَ تَعْلَمُ هَذَا الأَمْرَ - فَيُسَمِّيهِ مَا كَانَ مِنْ شَىْءٍ - خَيْرًا لِي فِي دِينِي وَمَعَاشِي وَعَاقِبَةِ أَمْرِي - أَوْ خَيْرًا لِي فِي عَاجِلِ أَمْرِي وَآجِلِهِ - فَاقْدُرْهُ لِي وَيَسِّرْهُ لِي وَبَارِكْ لِي فِيهِ وَإِنْ كُنْتَ تَعْلَمُ -
(2)
Allahumma inni astakhiruka bi ‘ilmika wa astaqdiruka bi qudratika wa as’aluka min fadlikal-‘azim, fa innaka taqdiru wa la aqdir, wa ta’lamu wa la a’lam, wa Anta ‘allamul-ghuyub. Allahumma in kunta ta’lamu hadhal-amra (then the matter should be mentioned by name) ma kan min shay’in khairan li fi dini wa ma’ashi wa ‘aqibati amri, aw khairanli fi ‘ajili amri wa ajilihi, faqdurhu li wa yassirhu li wa barik li fihi. Wa in kunta ta’lamu
O Allah, I seek Your guidance (in making a choice) by virtue of Your knowledge, and I seek ability by virtue of Your power, and I ask You of Your great bounty. You have power, I have none. And You know, I know not. You are the Knower of hidden things. O Allah, if in Your knowledge, this matter (then it should be mentioned by name) is good for me in my religion, my livelihood and my affairs, or both in this world and in the Hereafter then ordain it for me, make it easy for me, and bless it for me. And if in Your knowledge]. Then saying similar to what he said the first time, except: Wa in kana sharran li fasrifhu ‘anni wasrifni ‘anhu waqdur li al-khair haithuma kana thumma raddini bihi (If it is bad for me then turn it away from me and turn me away from it, and ordain for me the good wherever it may be and make me pleased with it).’
Reference : Sunan Ibn Majah 1383
In-book reference : Book 5, Hadith 581
English translation : Vol. 1, Book 5, Hadith 1383