From the Italian sonare meaning simply "to sound," the sonata has undergone enough changes throughout music history to fill several encyclopedic volumes, as some scholars have indeed given us. Fortunately for us, however, sonata form nearly always refers to a single-movement structure used throughout the Classical period.
It's no wonder musical terms are confusing. The Classical period (with a capital C) shouldn't be confused with the very general (and misleading) term "classical" music. Roughly speaking, the Classical period extended from Mozart's birth to Beethoven's death. Mozart lived from 1756-1791 and Beethoven from 1770-1827, but for convenience let's round the period to between 1750 and 1820. (Borders between historical periods are always fuzzy, and Beethoven had already burst all conceivable boundaries of sonata form by 1820.)
What's most important about any musical form is not some dry, academic analysis but rather its dramatic implication. As soon as you have two notes, there is a relation between them: the second may be higher or lower in pitch, longer or shorter in duration, and softer or louder. The two notes will form an interval that is consonant or dissonant. (Even that is a fluid concept: the philosopher Plato suggested banning certain music modes two and a half millennia ago, and the tritone was considered the "devil's interval" during the Middle Ages. What's more, the very same notes may sound perfectly consonant in one context but totally dissonant in another, as explained in Piano Theory.)
Let's take a look at traditional sonata form in the Classical era. Generally, if a large-scale work is called a "sonata" (take the "Moonlight" Sonata for example), only one movement of it is actually in sonata form. It's nearly always the first movement (but in the case of the "Moonlight" Sonata it happens to be the last, since Beethoven was already very much experimenting by 1800). To make matters more confusing still, the first movement of a Classical symphony is invariably in sonata form... even though the whole composition isn't called a sonata!
Let's review: if it was written more or less between Mozart's birth and Beethoven's death, has several movements, the first of which is in sonata form, and is written for just one or two instruments, it's called a "sonata"... but if it's written for a full orchestra it's called a "symphony." Does that make sense? (Of course not.)
I know that's confusing, but bear with me and I promise to simplify things. So the "Moonlight" Sonata has three movements—each of which is essentially a self-contained piece—yet only one of them is "really" a sonata.
Now that movement will be divided into four sections: exposition, development, recapitulation and coda:
The exposition introduces the main themes. Since music is a dramatic art (it exists in time), think of the themes as individual characters in a drama, like a film. Indeed, each theme will almost certainly have a specific character: happy, sad, heroic, lyrical, or anything else.
A Classical-period sonata has two main themes. (Great composers hardly ever stick to textbook formulas and often used two theme groups, but let's keep things simple.) These themes nearly always contrast one another. Thus, if the first theme is happy, the second might be sad, and if the first is heroic the second might be lyrical.
If a work is titled, say, Sonata in C Major and the first movement is indeed in sonata form, then the first theme will be in the home key (the tonic, in this case C major).
What's interesting is that the second theme will be in the wrong key. It's most often in the dominant, so let's use that for our example. Thus, for our sonata in C major, the first theme will be in C major and the second theme will be in G major.
That is a conflict of interest... and now our sonata has a dramatic goal: the second theme has to get back to the tonic key. This is where the development enters into play...
Just like in a film, once the main characters (in this case the themes) are presented and the conflict has been established,the action heats up. Things can get frantic in a Classical sonata's development section: themes appear in fragmentary form, the composer will rapidly cycle through keys (none of them the "right" one) so fast it's impossible to tell which key we're in, major may become minor, and the section is fraught with dissonance. By the end of the development we will have reached the main theme once again...
Once the drama settles down some and the first theme returns (albeit no longer in the tonic key), it's largely a simple matter of repeating the exposition. Usually there will be some variants to keep things interesting. When the second theme returns, it will at long last be in the "right" key, the tonic (C major in our example). The tension has now been resolved (even subconsciously) and it's time to bring things to a close with the...
The coda is simply the conclusion. It's just like the dénouement in a movie or novel: the events that take place after the climax which bring the story to a satisfying close. (Music usually doesn't leave room for sequels, though.) As with all music theory, what's most important is how it sounds and what it means. Remember, all music is inherently dramatic, and great composers found all sorts of ways to burst the boundaries of conventional sonata form in order to express great musical thoughts and emotions.