The difference between appearance and reality is something of a perennial theme in many of Shakespeare's plays, and can be effectively explored in both Hamlet and Twelfth Night through consideration of how madness is presented. Hamlet of course famously declares his intentions in Act I scene 5 to pretend to be mad as a deliberate strategy in his quest for revenge against his uncle:
...As I perchance hereafter shall think meet
To put an antic disposition on...
It is this declaration of Hamlet's that creates such confusion between appearances and reality, as Hamlet is swift to don his guise as a madman, appearing in Ophelia's bedchamber in a very strange manner soon after. A massive question that the play has, however, is whether Hamlet really is mad or not. Certainly some of his actions seem to suggest that his madness is genuine, but then at other points he appears to be strictly rational.
In the same way, poor Malvolio, the most sober and respectable character in the entire play, is accused of being mad and locked up by Sir Toby Belch and his friends because of the way that he tries to court his mistress. Other characters appear to be mad or to be extremely foolish whilst the reality is perhaps harder to grasp. Note, for example, Viola's rather shrewd assessment of Feste, a fool, in Act III scene 1:
This fellow is wise enough to play the fool,
And to do that well craves a kind of wit...
Being a successful fool or pretending to be mad seems to actually paradoxcially involve a huge amount of wisdom and intelligence. What both plays do therefore is to blur the boundaries between what is real and what appears to be real in some areas, so that the audience is left feeling unsure of what they can actually see and what is just a performance.