A sonata is an instrumental composition with three or four movements, for solo piano or violin etc., or for a duet, usually one instrument being the piano accompaniment.
Sonata in Italian means "played" as opposed to "sung" as in the Italian word "Cantata". From the Renaissance (1450 - 1600) on, the word "sonata" was used to distinguish an instrumental piece from a vocal composition or "Cantata". The precise form was not laid down in this period, but it typically would resemble a simple song.
In the classical period, from the second half of the eighteenth century on, the sonata evolved into an important form of highly structured instrumental music. The sonata consists of three movements, in contrasting tempi, fast, slow, fast.
The first movement, usually marked Allegro, is in SONATA FORM, in which the themes are treated in a carefully ordered sequence. The second or slow movement is marked Andante, Adagio, Lento, or Largo, and is often like a song. The third movement marked Allegro or Presto is often a RONDO. The first and third movements are in the same key, but the second is in a different one.
Most sonatas have three movements, but a few have only two, notably Beethoven's two "Easy" sonatas for piano, Opus 49 numbers 1 and 2. These both miss out the middle slow movement. Some sonatas include a fourth movement, such as a minuet or a scherzo, before the final fast movement. Occasionally the third movement is in the form of a theme with variations.
Three other major categories of music use the same form as the sonata. The symphony (for orchestra), and much chamber music such as the string quartet, have four movements. The concerto (for soloist and orchestra) has only three movements. The idea of inserting a minuet before the last movement in symphonies and string quartets comes from Stamitz of the Mannheim school.
Mozart and Beethoven are the most famous sonata composers. Mozart wrote over forty violin sonatas and nineteen piano sonatas. Haydn wrote many piano sonatas, mostly shorter and apparently simpler than Mozart's and Beethoven's, but every one of them is an absolutely delightful gem. Beethoven composed thirty-two piano sonatas, some of his most famous are the Pathetique Sonata (op. 13), the Moonlight Sonata (op. 27, no. 2), the Pastoral Sonata (op. 28), and the Appassionata Sonata (op. 57). He also wrote violin and cello sonatas. His most famous violin sonata is probably the Kreutzer Sonata, op. 47.
Schubert wrote about ten piano sonatas, using a more lyrical style but still in classic form. Mendelssohn wrote a violin sonata, and two cello sonatas. Even Chopin and Liszt wrote a few sonatas.
Brahms, a late romantic composer, used the classic sonata form. His sonatas for violin, piano, and clarinet were written between 1850 and 1900.