Istikhara literally means to 'Seek for the best’; it is a form of supplication. Istikhara also means to seek goodness from Allah (Glory be to Him), meaning when one intends to do an important task they do istikhara before the task. The one who does the istikhara is as if they request Allah (Glory be to Him), Almighty to guide for any matter which is better in this world and hereafter.
Linguistically al-istikharah comes from the verb istikharah which means ‘seeking / requesting guidance in what is good.’ so, al-istikharah is the noun for request or action. While in the islamic terminology al-istikharah means that a servant seeks guidance from his lord upon the manner described by the Prophet Muhammad (May Allah honour Him and grant Him peace) by praying two rakah of supererogatory prayer, then supplicating with the specific du’aa for al-istikharah.
Allah (Glory be to Him), the most high and the most merciful, ordained salaat al-istikharah for him whenever he faces an obstacle or is concerned about an affair: he consults his creator and seeks his guidance with regard to it because Allah (Glory be to Him), alone is the knower of Ghaiyab (unseen), he alone is the most knowledgeable about the reality of the affairs and their results, their benefits from their harms, their good from their evil, in this world and the hereafter: “and with him are the keys of unseen, none know them but he. And he knows whatever is there in the earth and in the sea. Not a leaf falls but by his knowledge; there is not a grain in the darkness (or the depth) of the earth, nor any flesh or dry (green or withered) but is written in a clear record.”Qur’an.Surah an’am 6:59 
This "prayer for guidance" is often used to help in important decision-making. Anytime a Muslim is making a decision, he or she should seek Allah's guidance and wisdom. Allah (Glory be to Him), alone knows what is best for us, and there may be good in what we perceive as bad, and bad in what we perceive as good.
Allah (Glory be to Him), said in Qur’an: Consult them in the affairs. Then when you have taken a decision, put your trust in Allah (Glory be to Him), certainly, Allah (Glory be to Him), loves those who put their trust (in Him). Quran.Surah A’le Imran 3: 159
If you are ambivalent or unsure about a decision you have to make, there is a specific prayer for guidance (Salat-l-Istikhara) that you can do to ask for Allah's help in making your decision. Should you marry this certain person? Should you attend this graduate school? Should you take this job offer or that one? Allah (Glory be to Him), knows what is best for you, and if you are not sure about a choice that you have, seek His guidance.
The Prophet Muhammad (May Allah honour Him and grant Him peace) said, "If one of you is concerned about some practical undertaking, or about making plans for a journey, he should perform two cycles (rak'atain) of voluntary prayer." Then he/she should say read a particular du'a for Istekhara. Sahih Al Bukhari vol.2:263 (6841 NE), Abu Dawood vol.1:1533, Sunan Nisa 3253,Tirmidhi 480, Ibn majah 1383 andMusnad Ahmad Vol 3:344.
Allahumma inni astakheeruka bi ilmika. Wa'astaq-diruka biqudratik. Wa'as'aluka min fazlikal-azeem. Fa'innaka taqdiru wala aqdir. Wa talamu wala-lamu. Wa'anta-allamul ghuyoob. Allahumma in kunta talamu anna (hazal-amra*) khayrul-lee fi deenee wama ashi wa azila amri wa'ajilah, faqdurhu lee, wayassirhu lee, summa-barik lee fih. Wa'in kunta talamu anna (hazal-amra*) sharrul-lee fi deenee. Wama-ashi. Wa azila amri. Wa'azilahu. Fasrifhu annee. Wasrifnee anh. Waqdur leyal-khayr haytho kana. summa arzini bihi.
* When making the du'a, the actual matter or decision should be mentioned instead of the words "hazal-amra" ("this matter"). After doing salat-l-istikhara, you may feel more inclined toward a decision one way or the other.
Oh Allah (Glory be to Him),! I seek Your guidance 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. Oh Allah (Glory be to Him),! If in Your knowledge, (this matter*) is good for my religion, my livelihood and my affairs, immediate and in the future, then ordain it for me, make it easy for me, and bless it for me. And if in Your knowledge, (this matter*) is bad for my religion, my livelihood and my affairs, immediate and in the future, 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 content with it. 
Note:It is not compulsory that you read this salah in night or before sleep. and its not compulsory that you may get a dream after this salah. After this salah, Inshallah you will be confident with the decision as Allah (Glory be to Him), says in Qur’an.Surah A’le Imran 3: 159 - put your trust in Allah (Glory be to Him).