Within the context of the plot, the masque in act 4 of The Tempest occurs because Prospero has Ariel summon spirits to put on a small play to celebrate Miranda and Ferdinand’s engagement. He tells Ariel, “I must / Bestow upon the eyes of this young couple / Some vanity of mine art.” Prospero wants to celebrate and impress his daughter and her fiancé.
During the play, Prospero says, in an aside, “I had forgot that foul conspiracy of the beast Caliban, and his confederates, against my life: the minute of their plot is almost come.” At this point, the masque changes from a celebration to a catalyst for Prospero’s reflections. He sees the end of the masque, when the spirits disappear, as the dissolution of everything, including “the great globe itself.” In Prospero’s mind, humans are composed of “such stuff as dreams are made on,” which will fade and dissolve as well; their lives are “little” and “rounded with a sleep.”
In the work as a whole, the masque functions to demonstrate the mutability of a life through both a microscopic and macroscopic view. Just as the spirits fade after the play, so will Prospero, the audience of the masque. Similarly, when The Tempest itself ends, the audience of the play will disperse. These concentric levels demonstrate the audience’s mortality. Therefore, the masque in act 4 of The Tempest functions as a reminder that human life is short and fades quickly.
In writing the masque, one could argue that Shakespeare was building a bridge from fantasy to reality, from the action on stage to the royal audience for whom the masque was performed. Shakespeare is breaking the fourth wall, inviting his audience to participate in the action on stage.
Prospero himself is ideally placed to straddle these two different worlds. He lives in the real world, the world of the remote desert island that has become his own little kingdom. Yet he also inhabits a parallel universe governed by the laws of magic. He must make a transition between these two worlds if he's to return to Milan, where he will be re-established as Duke. In that sense, Prospero's imminent fate parallels that of his creator, Shakespeare, whose last play this is and who will now give up his literary magic and retreat to the ordinary everyday world.
The masque in act 4 of The Tempest is, in terms of the plot, designed as an entertainment to celebrate Ferdinand and Miranda's marriage, just as one might have a wedding band today. Prospero shows the couple that he loves them by getting all his spirits to bless their marriage. Masques of all kinds, including for weddings, were becoming very popular at the time Shakespeare was writing this play, though their emphasis on music and spectacle over dialogue made them very different from his kind of work.
On another level, the masque provides the occasion for the "our revels now are ended" speech. Prospero compares the "pageant faded" to the "great globe itself," which will also dissolve and "leave not a rack behind." Prospero lives in a fictional world himself, so there is a triple layering going on here. The pageant dissolved by being interrupted, the play will shortly dissolve with the final lines, and the real world will dissolve when it reaches its end. Some people read these lines as "Shakespeare's goodbye to the theatre," since The Tempest was one of the last plays he wrote. Whether this is true or not, the masque allows Shakespeare to include this deeply reflective speech on the impermanence of theatrical illusion and of human life itself.
In Act IV, Scene I, Prospero decides to put on “a show,” using magic, for Ferdinand and Miranda. He summons the spirits of Juno, Ceres, and Iris. Iris, the goddess of the rainbow, calls Ceres, the goddess of agriculture. Juno arrives last, but she is the most important, as she is the goddess of marriage and childbirth.
The goddesses commence to bless the marriage of Ferdinand and Miranda. Juno promises: “Honour, riches, marriage-blessing, Long continuance, and increasing.. “ and Ceres promises: “Earth's increase, foison plenty, Barns and garners never empty, Vines and clustering bunches growing…” After the goddesses depart, Iris conjures up some nymphs and land reapers and there is music and dancing. “Answer your summons; Juno does command: Come, temperate nymphs, and help to celebrate "A contract of true love; be not too late…” The nymphs appear; she then summons the reapers: “You sunburnt sicklemen, of August weary, Come hither from the furrow and be merry…” The nymphs and reapers dance until Prospero realizes that he has forgotten the plot against his life, then they vanish.
The purpose of this scene and the masque is to show that Prospero is pleased by the marriage between Ferdinand and Miranda; so pleased, in fact, that he is using his magic, for once, to do something good. The goddesses he calls bless the marriage with fertility and happiness. It is Prospero’s wedding present to the two. It is also speculated that Shakespeare put this in to honor King James, whose daughter had just been married.