The Canon 7D has 17.9 million pixels: 5184 pixels by 3456 pixels. This is the maximum resolution of the sensor. It’s possible to get the 10 and 4.5 megapixels with the mRAW and sRAW formats.

The Canon 7D has three JPEG sizes: Large 17.9 megapixels, just like the RAW format, 8 and 4.5 megapixels. Since the image / pixels are the same, why are the JPEG photos so much smaller than the RAW photos?

RAW photos are 14 bit files.

   5184 pixels by 3456 pixels = 17.9 megapixels
   17.9 megapixels times 14 bits = 250.6 million bits
   250.6 million bits divided by 8 = 31.3 Megabytes

There were a couple of mistakes in the post, and they were corrected by Yaniv and are noted by crossing.

31.3Mb is the maximum size of the RAW photos, but it will often be smaller depending on the photo such as sky, black shadows… For me, they are usually around 23 MegaPixels Megabytes.

JPEG photos are 8 bit files. There are 3 colours per pixel, Each colour is 8 bits or 1 byte so it is 24-bit per pixel, or 3 bytes.

    5184 pixels by 3456 pixels = 17.9 megapixels
    17.9 megapixels times 8 bits = 143.2 million bits
    143.2 million bits times 3 for each colour = 429.6 million bits
    429.6 million bits divided by 8 = 53.7 Megabytes

Then there is the compression as set by the compression ratio. The compression is like similar to WinZip on Windows or BetterZip on Mac. But contrarily to Winzip which is a lossless compression, the JPEG compression causes losses. Each time you make a change and save the changes, there are losses in the photo quality. And that’s why RAW photos have a much better image quality but the photos always have the same number of pixels, just a lower quality.

Now, how come (uncompressed) JPEGs are larger than RAW? This is because JPEGs have three 8 bit color channels per pixel, while each pixel in a RAW array contains just ONE color information. The other two color channels are obtained by interpolation from the neighboring pixels. See Bayer Pattern interpolation for more details.

— Yaniv