Sunan an-Nasa'i, Volume 4, Book 26, Hadith 3255 (DarusSalam) ⓘ
It was narrated that Jabir bin 'Abdullah said: "The Messenger of Allah used to teach his Companions to perform Istikharah in all matters, just as he used to teach them Surahs from the Qur'an. 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: Allahumma inni astakhiruka bi 'ilmika wa astaqdiruka bi qudratika wa as'aluka min fadlika, fa innaka taqdiru wa la aqdir, wa ta'lamu wa la a'lam, wa anta 'allam al-ghuyub. Allahumma in kunta ta'lamu anna hadhal-amra khayrun li fi dini 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 dini wa ma'ashi wa 'aqibati amri fasrifhu 'anni wasrifni 'anhu waqdur li al-khayr haythu kana, thumma radini 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 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 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 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.)"
أَخْبَرَنَا قُتَيْبَةُ، قَالَ حَدَّثَنَا ابْنُ أَبِي الْمَوَالِ، عَنْ مُحَمَّدِ بْنِ الْمُنْكَدِرِ، عَنْ جَابِرِ بْنِ عَبْدِ اللَّهِ، قَالَ كَانَ رَسُولُ اللَّهِ صلى الله عليه وسلم يُعَلِّمُنَا الاِسْتِخَارَةَ فِي الأُمُورِ كُلِّهَا كَمَا يُعَلِّمُنَا السُّورَةَ مِنَ الْقُرْآنِ يَقُولُ " إِذَا هَمَّ أَحَدُكُمْ بِالأَمْرِ فَلْيَرْكَعْ رَكْعَتَيْنِ مِنْ غَيْرِ الْفَرِيضَةِ ثُمَّ يَقُولُ اللَّهُمَّ إِنِّي أَسْتَخِيرُكَ بِعِلْمِكَ وَأَسْتَعِينُكَ بِقُدْرَتِكَ وَأَسْأَلُكَ مِنْ فَضْلِكَ الْعَظِيمِ فَإِنَّكَ تَقْدِرُ وَلاَ أَقْدِرُ وَتَعْلَمُ وَلاَ أَعْلَمُ وَأَنْتَ عَلاَّمُ الْغُيُوبِ اللَّهُمَّ إِنْ كُنْتَ تَعْلَمُ أَنَّ هَذَا الأَمْرَ خَيْرٌ لِي فِي دِينِي وَمَعَاشِي وَعَاقِبَةِ أَمْرِي - أَوْ قَالَ فِي عَاجِلِ أَمْرِي وَآجِلِهِ - فَاقْدُرْهُ لِي وَيَسِّرْهُ لِي ثُمَّ بَارِكْ لِي فِيهِ وَإِنْ كُنْتَ تَعْلَمُ أَنَّ هَذَا الأَمْرَ شَرٌّ لِي فِي دِينِي وَمَعَاشِي وَعَاقِبَةِ أَمْرِي - أَوْ قَالَ فِي عَاجِلِ أَمْرِي وَآجِلِهِ - فَاصْرِفْهُ عَنِّي وَاصْرِفْنِي عَنْهُ وَاقْدُرْ لِي الْخَيْرَ حَيْثُ كَانَ ثُمَّ أَرْضِنِي بِهِ - قَالَ - وَيُسَمِّي حَاجَتَهُ " .
also referenced under: Hadith 3253 (Reference) & Book 26, Hadith 58 (In-Book)