A common technique in Shakespeare and other playwrights is that of creating a play within a play or staging a play within a play.
Sometimes, another play is literally staged, as in the case of Shakespeare's Midsummer Night's Dream. In that comedy, most of the play's final act is taken up by a performance of Pyramus and Thisbe, a story which the educated among Shakespeare's audience would have known from Ovid's Metamorphoses, a Latin epic poem written 1500 years earlier. Ovid's story is completely tragic and may have influenced Shakespeare's Romeo and Juliet. Ovid's tragic story would not have been appropriate in the context of Midsummer Night's Dream, a comedy that ends with the marriage of three couples. Accordingly, the production of Pyramus and Thisbe in Shakespeare's comedy is given a light tone as male merchants perform it and young man named Francis Flute plays the role of the young woman Thisbe.
In contrast to the literal staging of Pyramus and Thisbe in Midsummer Night's Dream, other Shakespearean works have more figurative plays staged within them. For example, in Shakespeare's Twelfth Night, one could identify at least two other "plays" going on within that comedy. One figurative play involves the female Viola dressing up a man named Cesario and becoming a close and confidential servant of Orsino, with whom she falls in love. Another figurative play involves the maidservant Maria trying to trick Malvolio into thinking that Olivia is in love with him. Maria functions like the writer and director of this play. She writes a letter in Olivia's style of handwriting and later enlists Feste to pretend to be Sir Topas and convince Malvolio that he (Malvolio) is insane.
So, in Shakespeare's plays, we can find at least two different types of plays within a play. Some plays are literal ones, like the staging of Pyramus and Thisbe; others are more figurative ones, as in Twelfth Night, where one character will pretend to be someone else or where one character will "direct" another character or characters to trick another character or characters. This latter type of play within a play is sometimes called metatheater.