Praise be to Allah.
The description of Salaat al-Istikhaarah was reported by Jaabir ibn Abd-Allaah al-Salami (may Allaah be pleased with him) who said:
The Messenger of Allaah (peace and blessings of Allaah be upon him) used to teach his companions to make istikhaarah in all things, just as he used to teach them soorahs from the Quraan. He said: If any one of you is concerned about a decision he has to make, then let him pray two rakahs of non-obligatory prayer, then say: Allaahumma inni astakheeruka bi ilmika wa astaqdiruka bi qudratika wa asaluka min fadlika, fa innaka taqdiru wa laa aqdir, wa talamu wa laa alam, wa anta allaam al-ghuyoob. Allaahumma fa in kunta talamu haadhal-amra (then the matter should be mentioned by name) khayran li fi aajil amri wa aajilihi (or: fi deeni wa maaashi wa aaqibati amri) faqdurhu li wa yassirhu li thumma baarik li fihi. Allaahumma wa in kunta talamu annahu sharrun li fi deeni wa maaashi wa aaqibati amri (or: fi aajili amri wa aajilihi) fasrifni anhu [wasrafhu anni] waqdur li al-khayr haythu kaana thumma radini bihi (O Allaah, 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 Allaah, 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-Bukhaari, 6841; similar reports are also recorded by al-Tirmidhi, al-Nisaai, Abu Dawood, Ibn Maajah and Ahmad).
Ibn Hijr (may Allaah have mercy on him) said, commenting on this hadeeth:
Istikhaarah is a word which means asking Allaah to help one make a choice, meaning choosing the best of two things where one needs to choose one of them.
Concerning the phrase The Messenger of Allaah (peace and blessings of Allaah be upon him) used to teach us to make istikhaarah in all things, Ibn Abi Jamrah said: It is a general phrase which refers to something specific. With regard to matters that are waajib (obligatory) or mustahabb (liked or encouraged), there is no need for istikhaarah to decide whether to do them, and with regard to matters that are haraam (forbidden) or makrooh (disliked), there is no need for istikhaarah to decide whether to avoid them. The issue of istikhaarah is confined to matters that are mubaah (allowed), or in mustahabb matters when there is a decision to be made as to which one should be given priority. I say: it refers to both great and small matters, and probably an insignificant issue could form the groundwork for a big issue.
The phrase If any one of you is concerned appears in the version narrated by Ibn Masood as: if any one of you wants to do something
Let him pray two rakahs of non-obligatory prayer. This is mentioned to make it clear that it does not mean fajr prayer, for example. Al-Nawawi said in al-Adhkaar: He can pray istikaarah after two rakahs of regular sunnah prayer done at zuhr for example, or after two rakahs of any naafil prayers whether they are regularly performed or not It seems to be the case that if he made the intention to pray istikhaarah at the same time as intending to pray that particular prayer, this is fine, but not if he did not have this intention.
Ibn Abi Jamrah said: The wisdom behind putting the salaat before the duaa is that istikhaarah is intended to combine the goodness of this world with the goodness of the next. A person needs to knock at the door of the King (Allaah), and there is nothing more effective for this than prayer, because it contains glorification and praise of Allaah, and expresses one's need for Him at all times.
The phrase then let him say would seem to imply that the duaa should be said after finishing the prayer, and the word thumma (then) probably means after reciting all the words of the salaat and before saying salaam.
The phrase O Allaah, I seek Your guidance by virtue of Your knowledge is explaining because You know best. Similarly, by virtue of Your power most likely means seeking Your help. I seek ability (astaqdiruka) means I ask You to give me the power or ability (qudrah) to do whatever is being asked for, or it probably means I ask You to decree (tuqaddir) this for me. So it may mean making it easy.
I ask You of Your great bounty refers to the fact that Allaah gives out of His great generosity, but no one has the right to His blessings. This is the opinion of Ahl al-Sunnah.
You have power, I have none. And You know, I know not refers to the fact that power and knowledge belong to Allaah alone, and the slave has no share of them except what Allaah decrees for him.
O Allaah, if in Your knowledge this matter According to one report, he should mention it by name. It is apparent from the context that he should state it, but it is probably sufficient to be thinking of the matter whilst making this duaa.
Then ordain it for me means make it happen for me or it may mean make it easy for me.
Then turn it away from me, and turn me away from it means so that my heart will no longer feel attached to it after it has been turned away.
Make me pleased with it means make me content with it, so that I will never regret asking for it or be sorry that it happened, because I do not know how it will turn out, even if at the time of asking I am pleased with it.
The secret is that ones heart should not be attached to the matter in question, because that will result in a person becoming restless. Being pleased with something means that ones heart is content with the decree of Allaah.
(Summarized from the commentary of al-Haafiz Ibn Hijr (may Allaah have mercy on him) on the hadeeth in Saheeh al-Bukhaari, Kitaab al-Dawaat and Kitaab al-Tawheed.).