An illusion (māyā) is something false or without real existence. Some misinformed people believe that the Buddha taught that everything is an illusion created by the mind and that nothing really exists. This is one of several examples of where a doctrine of Vedantic Hinduism has been mistakenly attributed to the Buddha. So what did the Buddha mean when he said: 'Everything is unreal' (sabbaṃ vitathaṃ, Sn.9)?
Idealism is the concept that everything is just a creation of the mind, the 'dance' or 'play' (līlā) of God, according to Vedanta. The extreme opposite of this is naive realism, the concept that everything is exactly as it appears to be. Both these ideas are false, the first much more so than the second, and the Buddha subscribed to neither of them.
Very clearly the external world exists in the real sense of the word. The elements of existence - earth or solidity (paṭhavī), water or fluididity (āpo), fire or caloricity (tejo) and wind or movement (vāyo) - exist independently of our minds. However, when the external world impinges on our senses we react by projecting ideas, values, assumptions and expectations onto it. As a result, what we perceive is often more a product of our minds than the qualities of the object itself. This is what the Buddha called 'the distortion of perception' (saṭṭā vipullāsa, A.II,52).
The value of meditation is that in watching the mind we see its projecting and distorting tendency and are less likely to be led astray by it. In time, as the mind becomes utterly still and clear, it stops projecting and sense objects reveal themselves to us as they are. The ordinary person sees everything through the filter of his or her desires, memories, prejudices and wants; the enlightened person 'sees things as they really are' (yathābhūtaṭāṇadassana).