A metaphor is a figure of speech or trope. The rhetorical figures are divided into tropes, which use language in a way that goes beyond literal sense, and the schemes, which use language literally, but employ particular arrangements that have proved effective.
Though metaphors are similar to similes because they are both figures that deal with comparison, a simile is a comparison that is explicitly stated using a word such as like or as, a metaphor is a comparison that literally states that one thing is another, and requires the reader or listener to perceive that this is not a factual statement, but one that must be figuratively interpreted. So, while a simile might say “O, my Luve’s like a red, red rose,” a metaphor would say, “O, my Luve’s a red, red rose,” — to misquote Robert Burns — and leave it to the reader to work out.
A second difference between metaphor and simile is that the first can be played out in more detail, in which case, it is called an extended metaphor. A famous example is the scene in Shakespeare’s play Hamlet (Act III, scene 2) that is argued in terms of music, specifically, recorder playing technique, with Hamlet saying,
“You would play upon me; you would seem to know my stops; you would pluck out the heart of my mystery; you would sound me from my lowest note to the top of my compass; and there is much music, excellent voice, in this little organ, yet cannot you make it speak. ’Sblood, do you think I am easier to be played on than a pipe? Call me what instrument you will, though you can fret me, you cannot play upon me.”
"My love is a red rose" is an example of a metaphor.
Here, Hamlet accuses Rosencrantz and Guildenstern of trying to gain insight into him, deceive him, and manipulate him, and he ends by assuring them that this is not the case. In doing this, he continually speaks of himself as if he were a recorder and they were musicians, but he still leaves something to be inferred by both his listeners and the audience.
Sometimes an extended metaphor is less mysterious and includes a definition of all the correspondences to help the audience understand what is meant, as in this example from Norman Cousins:
A metaphor compares two dissimilar objects like an orange and an apple, without using the words "like" or "as."
“The library is not a shrine for the worship of books. It is not a temple where literary incense must be burned or where one's devotion to the bound book is expressed in ritual. A library, to modify the famous metaphor of Socrates, should be the delivery room for the birth of ideas — a place where history comes to life.”