To give a bit more detail on the format: the image to be encoded is divided into 8x8 pixel chunks. Assuming the image is colour, it is converted from RGB colour space to YUV colour space. Each of the three colour components Y, U and V then has a 2D discrete cosine transform applied to it. Since it's an 8x8 block, this DCT has 64 coefficients, but the nice thing is that many of them are close to zero. So, depending on the quality setting, you throw away the coefficients that are closest to zero ... the higher the quality setting, the less coefficients you throw away. You then compress the remaining coefficients using Huffman compression and that's it; you have a JPEG file.

This is also the source of artefacts in uncompressed JPEG images. If you look at a JPEG image closely, especially a poor quality one, you can sometimes see the edges of the 8x8 blocks, where the DCT on one side doesn't match the DCT on the other.