Abu Salamah  رحمه الله reported that he used to have dreams that made him ill (from fear or worry) - until he heard Abu Qatadah رضي الله عنه mention that he had the same problem, so Allaah's Messenger صلى الله عليه وسلم told him: "A pleasant (or good, or truthful) dream is from Allaah, and a bad dream is from Shaytaan. When one of you has a good dream (that he likes), let him expect good, and avoid relating it except to those whom he loves. And when he has a dream and dislikes any part of it, let him seek Allaah's protection from its evil and from Shaytaan's evil, and let him lightly spit - three times - on his left side, and avoid relating it to anyone. Indeed, it will then not harm him." 
Abu Sa'eed al-Khudri رضي الله عنه reported that he heard the Prophet صلى الله عليه وسلم say: "When one of you has a dream that he likes - indeed, it is only from Allaah, so let him praise Allaah for it and relate it (to his beloved ones). And if one of you has a dream that he hates - indeed, it is only from Shaytaan, so let him seek Allaah's protection from its evil, and let him not mention it to anyone: it will then not harm him." 
Abu Hurayrah رضي الله عنه reported that the Prophet صلى الله عليه وسلم said: "Dreams are of three categories: a good dream that has glad tidings from Allaah, a terrifying dream from Shaytaan, and a dream about what concerns a person. When one of you has a dream that he dislikes, let him rise from his sleep and pray, and let him not relate it to other people." 
Abu Hurayrah رضي الله عنه also reported that the Prophet صلى الله عليه وسلم said: "When one of you has a dream that he likes, let him narrate it (to his beloved ones) and interpret it; and when one of you has a dream that he dislikes, let him neither narrate it nor interpret it." 
Jaabir Ibn 'Abdillaah رضي الله عنهما reported that Allaah's Messenger صلى الله عليه وسلم said: "When one of you has a dream that he dislikes, let him spit (lightly) three times on his left side, ask Allaah three times to shelter him from Shaytaan, and turn over from the side on which he was sleeping." 
And 'Awf Ibn Maalik reported that the Prophet صلى الله عليه وسلم said: "Dreams are of three categories: scary dreams from Shaytaan - to depress the human being, things that concern a person during his wakefulness, so he sees them in his dream, and dreams that are a part of forty six parts of prophethood." 
From the above ahaadeeth, we surmise that there are three main categories of dreams:
(1) Truthful dreams (inspired by Angels).
(2) Terrifying dreams (whispered by Shaytaan).
(3) Mixed up medleys (dreamer's thoughts, concerns, etc).
The second and third categories are meaningless in the sense that they have no useful interpretation. Shaykh Muhammad Ibn Saalih al-'Uthaymeen رحمه الله said: "During its minor death (i.e. sleep), the soul sees dreams and visions that divided into three categories: pleasant dreams, hateful dreams, and dreams that consist of meaningless and pointless things. The latter could be from Shaytaan's teasing, from echoing personal concerns, or from other reasons." 
Truthful dreams contain signals regarding events or other things that Allaah سبحانه و تعالى created or will create.
Imaam Ibn 'Abdil-Barr رحمه الله said: "It should be believed that a truthful dream is from Allaah is a part of prophethood. It reflects great wisdom and kindness from Allaah, which adds to a believer's faith. I do not know any difference in this regard among the people of religion and truth, whether they are from the followers of opinion or of hadeeth reports. No one rejects (the value of) dreams except the atheists and a small group ofmu'tazilah (a philosphical deviant sect)... If a dream is not mixed up medleys or a nightmare, it is truthful. It can even be seen by a non-believer or a sinner, such as the dreams of the King of Egypt and of the two prison-mates of Prophet Yoosuf (peace be upon him)..." 
The following steps may help in distinguishing a truthful dream from a meaningless dream:
(a) First, the dreamer should exclude any dream that is apparently from the third (thoughts/concerns, etc) category - whether the dream is pleasant or unpleasant. A meaningless dream would normally be a reflection of the dreamer's thoughts or concerns, a result of a physical weakness (such as fever) or tendency (such as hunger or thirst), or a total mix-up that shows no theme.
(b) If the dream is unpleasant, the dreamer should ponder on whether it brings baseless terror, which means that it is from Shaytaan, or if it carries subtle warnings and legitimate pointers, which could mean that it is truthful.
(c) If the dream is pleasant and passes test (a), or is quite notable and brings some original thoughts that appear to be alien to daily life and experience, then it may very possibly be truthful.
Imaam Ibn Khaldoon رحمه الله said: "A truthful dream has signs that attest to its truthfulness and legitimacy, so the dreamer would feel the glad tidings from Allaah because of what he was inspired with during his sleep. Among these signs are the following:
(i) Quick awakening after having the dream - as though the dreamer rushes to regain wakefulness because of the importance of the inspiration he received (in the dream).
(ii) The dream remains imprinted and fixed, in full detail, in the dreamers memory." 
While there is no solid proof from Islamic texts for Imaam Ibn Khuldoon's above statement, experience shows their correctness in many cases of truthful dreams.
Based on what they symbolise, truthful dreams can further be divided into three classes: pleasant, unpleasant or forewarning, and admonishing.
Imaam ad-Daawoodi رحمه الله said: "Truthful dreams may include warnings as well as glad-tidings." 
And Imaam Hakeem at-Tirmidhi رحمه الله said: "A truthful dream tells a truth, which may be a glad tiding, a warning, or a reprimand." 
(1) Pleasant: A good fortune that will reach him; for example, seeing himself in Jannah.
(2) Unpleasant or forewarning: A harm that may afflict him (which may be possible to avert in some cases); for example, seeing a fire burning some of his valuables.
(3) Admonishing: A reprimand for a shortcoming or sin, or an encouragement for improvement; for example, seeing himself prevented from entering Jannah unless he takes a bath.
Terrifying or bad dreams, also known as nightmares, are insinuated by Shaytaan to alarm or distress people. Such dreams have no real meaning or interpretation. They should be distinguished from foreboding truthful dreams that we have mentioned above.
The harm of bad dreams is merely psychological. It lies in frightening, disturbing, depressing, or worrying people. By following the guidelines provided in the Sunnah, their evil effects can be completely annulled. Furthermore, this may even reduce some worries in regard to truthful foreboding dreams.
Imaam al-Qaadi 'Iyaad رحمه الله said: "An 'unpleasant or evil' dream means either that it is apparently unpleasant (i.e. from Shaytaan), or that it has an unpleasant interpretation (for a foreboding truthful dream). The wisdom in keeping this uncertainty - though the dream might be truthful - may be to spare the dreamer from worrying about its unpleasant interpretation... If no one interprets it for him, he remains hopeful that it might have a good interpretation, or that it is meaningless, and this would reduce his worry." 
As an example, let us assume that a person had a dream that he was sinking in quicksand without being able to move any limb to save himself, and that his calls for help were muffled. This could be a nightmare, and could also be a truthful dream indicating that the dreamer will sink in debt or some other calamity without finding anyone to help him. If he treats this dream as a nightmare and performs the isti'aadhah and other protective measure, this dream would not harm him if it truly is a nightmare. Furthermore, if it is a truthful foreboding dream, Allaah سبحانه و تعالى would reduce or eliminate its harm by virtue of the dreamer's supplication.
Adghaath or medleys are the most common category of dreams. They have various reasons, such as habits, echoed-thoughts about matters that concern the dreamer, reactions to his physical health condition, and Shaytaan's delusions. Medleys have no useful interpretation.
In regard to this category of dreams, al-Haafidh Ibn Hajar رحمه الله said: "Dreams for which the dreamer finds no consequences in his wakefulness arise from things that concerned him before going to sleepm so he dreams about them. This type has no harm or benefit." 
Examples of adghaath dreams: A person with the need to relieve himself may see that he is earnestly looking for a toilet; a person with a fever may see himself walking in a hot desert or under a midday sun; a ringing alarm clock near him may initiate a dream of a train making whistling noises, etc.