A trilogy is, in its most basic form, a story in three parts.
It's one of the most common methods of telling a story (other than the simple standalone story), and as such it's one of the most obvious and effective examples of the Rule of Three. These stories tend to follow the Three-Act Structure: the first part will set the story up, the second part will feature a "rising action", where the story becomes much more apparent, and the third act resolves the points raised by the first act. Because trilogies often (but not always) comprise stories that are released apart from each other, the parts can also contain the three-act structure in themselves.
Trilogies where the second and third parts are obviously more interlinked than the first (most often due to publishers requesting more, but also due to pacing issues) can be found in Two-Part Trilogy. Series that were originally trilogies that have more than three entries go under Trilogy Creep.
The middle stories of a trilogy can often suffer from Middle Book Syndrome, where there is no start or end to the plot; for an example of this in a heptalogy (sequence of seven), Harry Potter and the Half-Blood Prince, apart from the subplot about the titular "prince", either takes plot threads from Order of the Phoenix or carries them to Deathly Hallows.
In some cases, a work is a "trilogy" only in the sense that it was printed in three books, either because the story was too long to print in one volume, or because the publisher thought a book that large wouldn't sell. Tolkien regarded The Lord of the Rings as a single novel, divided into six (non-standalone) books; publishing requirements forced him to print it as three volumes, and to come up with names for them. (The second volume, The Two Towers, suffers the most; it contains two entirely independent, overlapping stories, both of which start and end in the middle of things.) Releasing a novel in three parts became popular during the early days of printed novels, where the high cost of manual typesetting and printing meant that releasing a novel piecemeal allows the printer to judge the popularity of a story and whether it would be profitable to continue to print the second and third part. Jane Austen's Pride and Prejudice being a famous example of such a "triple-decker novel".
There are some examples of a "double trilogy" or a "triple trilogy", or, indeed, a "quadruple trilogy", where a story is split up into relatively separate trilogies. Star Wars is the most famous example of the second; The Saga of Darren Shan is a rare example of the last.