The description of Salat al-Istikharah was reported by Jabir ibn Abdullah al-Salami (ra) who said:
The Messenger of Allah (saw) used to teach his companions to make istikharah in all things, just as he used to teach them surahs from the Qur’an. 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:
Allahumma 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 allam al-ghuyoob. Allahumma 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. Allahumma 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 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.
The word istikharah itself means asking Allah (swt) to help one make a choice. Obviously, asking Allah (swt) is what we as humans do since we know that Allah (swt) chooses and plans the best.
Our beloved Prophet (saw) encouraged us to make istikharah in all things. However, everything in this case does not refer to things that are wajib (obligatory) or mustahhab (liked or encouraged). In those sorts of scenarios there is no need for istikharah since we have already been guided by Allah (swt) and His Messenger (saw). Rather, istikharah is supposed to be for issues that are mubaah (allowed), or in matters that are mustahhab matters when there is a decision to be made as to which one should be given priority.
The actual technique for istikharah starts with praying 2 rakahs of non-obligatory prayer. Ibn Abi Jamrah said, “The wisdom behind putting the salat before the duah is that istikharah is intended to combine the goodness of this world with the goodness of the next. What we are doing is essentially knocking at the door of the Almighty (swt) and there is nothing more effective for this than prayer.
The last part of the duah is interesting in the fact that we are asking Allah (swt) to keep make us distant and unattached to the issue we are praying about. 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 to istikharah is having a realization where a persons 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 Allah (swt). And Allah (swt) knows best.