To understand the nature and reason for Macbeth's visions and hallucinations, and how they determine his character, one has to understand the context in which they occur.
It is clear that even though Macbeth has concluded that he has to kill Duncan to become King of Scotland, he does not relish the task. He is overwhelmed by the thought of having to commit such a dreadful act and in a lengthy monologue he reasons that his purpose is too feeble, saying:
I have no spur
To prick the sides of my intent, but only
Vaulting ambition, which o'erleaps itself
And falls on the other.
He has reasoned that there are many reasons why killing Duncan would not be wise. In this state of mind, he tells Lady Macbeth that:
We will proceed no further in this business
He is, however, persuaded by her insistence, her criticism of his manhood and her promise to be cold towards him to continue with the dastardly deed.
It is in this context that Macbeth, when the time nears to commit the foul deed, hallucinates and sees a dagger appear before him. He is under intense pressure, for he has made a vow to his wife. He is anxious, afraid and overwhelmed by the thought of committing such a horrific crime. So overcome is he by all these factors that he imagines seeing the dagger, which is a representation of the evil he is about to commit. Macbeth realises this and questions this figment of his imagination:
art thou but
A dagger of the mind, a false creation,
Proceeding from the heat-oppressed brain?
The second time Macbeth is occasioned by an unwelcome vision is after he has had Banquo murdered. Once again, he has committed an utterly reprehensible act: the assassination of a best friend, confidante and ally. Banquo's ghost appears to him at the banquet table, sitting in his place. Macbeth addresses the spirit he imagines seeing:
Thou canst not say I did it: never shake
Thy gory locks at me.
Macbeth has turned pale with fear and his wife informs the gathering that he is having a fit, an illness that he has had since childhood. Macbeth, however, is horrified and sees the vision as '...that which might appal the devil'. When the ghost reappears, Macbeth is once again overcome with fear and orders the ghost to leave. Once the ghost vanishes he declares,
'Why, so: being gone,
I am a man again'.
It is clear at this point that Macbeth has been, and is, possessed by paranoia - he has begun seeing danger everywhere - there is considerable risk, even from the dead. In this state, he has begun to get rid of those he deems a threat, and no one is spared. Macbeth has now become rooted so much in his own evil that he cannot stop himself.
Finally, Macbeth undertakes a visit to the witches to seek their assurances that he is safe and protected by their charm. During this visit, he sees several visions, each with its own message. The first is the apparition of an armed head which informs him:
... beware Macduff;
Beware the thane of Fife.
The second apparition says the following:
Be bloody, bold, and resolute; laugh to scorn
The power of man, for none of woman born
Shall harm Macbeth.
... Macbeth shall never vanquish'd be until
Great Birnam wood to high Dunsinane hill
Shall come against him.
The fourth vision is one of Banquo, showing his hereditary line which follows into eternity. Banquo appears at the end. Macbeth is overwhelmed and utters the following:
Horrible sight! Now, I see, 'tis true;
For the blood-bolter'd Banquo smiles upon me,
And points at them for his.
Macbeth has reached a point where he feels so vulnerable that he needs guarantees from the evil sisters that he is safe. Since he mistrusts everyone, he ironically turns to the devil's disciples for comfort. Macbeth has lost all reason and is unable to see through the witches' paradoxes and equivocation. When he is later faced with the reality of their ambiguity, it is too late. He then only realises their deception and finally acknowledges their devastating and diabolical duplicity.
There are three very notable hallucinations that Macbeth experiences. One is the dagger that he sees floating before him just before he is about to murder Duncan. Just after he kills the king, he fancies he hears voices calling out that 'Macbeth does murder sleep!' (2.2. 33). Later, once he has become king, and arranged for the murder of Banquo, he sees Banquo's ghost. These visions and hallucinations all testify to the fact that he is slowly becoming unhinged. To begin with, he did not really have it in him to murder; he has to force himself to kill Duncan, and his hallucinations just before and after committing this crime demonstrate how disturbed he is over it. Once he begins his path of crime, however, he becomes ever more reckless, killing more and more, but this is essentially out of a sense of increasing despair - he feels he is beyond all salvation and this drives him slowly insane. This also happens to Lady Macbeth: her overriding sense of guilt and remorse manifests itself in her sleepwalking where she obsessively tries to scrub out bloodstains.
Macbeth is a play about power and the insanity it can bring. We see both Macbeth and Lady Macbeth, lose their grip on reality and it shows up in many forms.
One of the most significant visions we see is when the floating dagger accompanies Macbeth as he goes to murder King Duncan. Even Macbeth questions what he is seeing "Is this a dagger which I see before me?". We can see that Macbeth is having visions and questions the reality of what he is seeing.
"Art thou not, fatal vision, sensible to feel as to sight? Or art thou but a dagger of the mins, a false creation, proceeding from the heat-oppressed brain?" (Act 2, Scene 2)
The dagger is covered with blood, which represents the bloody course Macbeth and Lady Macbeth are headed down. The dagger is pointing like an arrow at the king's chamber. This is interesting as well, when a person's mind becomes splintered by insanity, sleep becomes useless. King Duncan was killed while he was sleeping restfully, while Macbeth is tormented and can't sleep.
Another example of how madness is shown in visions and not sleeping, is when Lady Macbeth is sleepwalking and has a hallucination of blood stains on her hands. She thinks her hands are covered in the blood of the innocent and she tries to wash it off, but it won't come off. Of course there is no real blood on her hands, but her splintered mind is seeing the blood stains. Both Macbeth and Lady Macbeth slowly slip into madness, and the hallucinations and visions they see show us this.