How do you know that what you see is as it is or is just an illusion?

An illusion is the mind's false interpretation of visual information. What you "see" is an image, and this image has to be identified by the brain, by comparing it to described or previously-experienced phenomena. Optical illusions are based on how the mind uses visual cues to simulate distant, three-dimensional, or moving objects. Magicians create illusions by establishing false parameters (before/after, continuity of motion, or the apparent location of objects and people).
Everyone has the potential for imagination - to see things as they might be or could be. But if something is observed by more than one person, and can be objectively separated from what we want, believe, or assume it to be, it must be considered "real".
You Can Never Really Be Sure
You can't know. Maybe one day, you wake up and you realize that your whole life was just a dream.
Illusions, Reality, and the Supernatural
In general, an observation is considered an illusion if it contradicts with what other people observe or have observed in the past. Vice versa, an observation is considered not an illusion if it is confirmed by observations of others. Suppose you are in a room with a friend. Suddenly you see a third person in the room. If your friend does not see that third person, it is probably an illusion. If he/she does see the person, it is probably not an illusion. Remember, that supernatural phenomena usually have many possible explanations. Maybe you have a special gift that causes you to see something your friend does not see. Maybe a supernatural person has the power to let you see something that others can't see. You should leave all options open, especially the option that it is an illusion, since the human mind is able to dream, even when you are awake.
There is a philosophical principle called "Occam's razor." This principle teaches that "entities must not be multiplied beyond necessity." Simply put, it means that if a surprising occurrence can be explained without resort to the intervention of an unknown, then that's probably the right explanation. If you sit down to watch television and it won't turn on when you press the "on" button of your remote, what is more likely:
Your spouse stumbled over the cord, accidentally unplugging the TV.
The batteries in your remote control are dead.
A ghost snuck in and decided that messing with you and your TV would be an interesting thing to do, because being dead is extremely boring.
Testing Reality
There is probably something like the Turing Test for Artificial Intelligence, except applied to the problem of distinguishing virtual reality, illusion and reality. When you can't tell the difference, it probably doesn't matter.