Hamlet, like Shakespeare's other plays, is written in a combination of verse (poetry) and prose (how we talk every day). But, as Polonius would say, there's method in the madness.
In Hamlet—like in most of Shakespeare's plays—the nobles typically speak in unrhymed "iambic pentameter" (also called "blank verse"). Don't let the fancy names intimidate you —it's pretty simple once you get the hang of it.
An "iamb" is an unaccented syllable followed by an accented one. "Penta" means "five," and "meter" refers to a regular rhythmic pattern. So "iambic pentameter" is a kind of rhythmic pattern that consist of five iambs per line. It's the most common rhythm in English poetry and sounds like five heartbeats: ba-DUM, ba-DUM, ba-DUM, ba-DUM, ba-DUM.
Let's try it out on these two lines from Hamlet:
and BY opposing END them? To DIE to SLEEP;
no MORE; and BY a SLEEP to SAY we END
Every second syllable is accented, so this is classic iambic pentameter. Well—not quite classic. You smarty-pants(es) in the audience probably noticed that there's a shift in the meter of the first line, so that two unaccented syllables follow each other. That's a little bit of poetic license there. Poets (and playwrights) hardly ever write in perfect meter, because perfect meter sounds like a nursery rhyme. Varying the meter draws attention to certain words (like "die" and "sleep" in this case) and helps the verse sound a little more natural.
That takes care of iambic pentameter. Since these lines have no rhyme scheme ("melt" and "dew" don't rhyme), we call it "unrhymed iambic pentameter," which is also known as "blank verse."
Blank verse is a pretty formal way to speak, so it's reserved for nobles and formal situations, like Claudius's address to the court in Act I, scene ii. Hamlet's soliloquies are in verse too, but he also speaks a lot of prose—which we think has something to do with how much role-playing he does.
Characters who aren't so high-class—like the gravediggers—don't get to speak in verse; they just talk. Hamlet himself, however, sometimes speaks in prose, even when he's being awfully poetic. Take, for instance, the following line:
How noble in reason! how infinite in faculty! in form, in moving, how express and admirable! in action how like an angel! in apprehension how like a god! the beauty of the world! the paragon of animals! And yet, to me, what is this quintessence of dust? (2.2.250)
That's high on the Poetry Richter scale yet it's written in prose. Any ideas why?