JPG is the file extension for JPEG files (Joint Photographic Experts Group, committee of ISO and ITU).
Lossless compression ensures that we will read back out of the file exactly the same data that we wrote into it, with absolutely no changes. Lossless is a desired necessary feature in like our bank checking account software, or in our Word or Excel or text editor program. Zip files are always lossless, and some image formats are lossless (PNG and TIF LZW), but JPG is not lossless.
JPG is lossy compression, necessary to be able to do such heroic feats of shrinking the file data so extremely. The process has to take liberties with the data to accomplish it. Lossy compression means we don't get exactly the same thing back out of the file that we thought we put in. Some detail is lost. We don’t lose pixels, we always get the same count of pixels back, but some those pixels may now be different colors (color is the only property of a pixel, and colors are the only thing representing image detail). Unexpected differences are image quality losses. These unexpected changes are called artifacts, false detail added by some external agent or tool, not naturally present (similar to the archaeology definition).
Some degree of this is in any JPG file, but it can still be high quality, or "good enough" quality if we don't go too far. The JPG artifacts cannot be undone, it is too late then, which is a strong argument (especially for important images) to keep the original images archived as unedited pristine, and only edit and use copies. Further, subsequent additional editing sessions of a JPG file involves more SAVES of the file, each of which do additional JPG compressions, which can add additional JPG artifacts (on top of previous artifact pixels). Which is another strong argument to preserve the original images, as a clean start over point.
A plug for raw files: There are choices, and one the many advantages of Raw images is that Raw images automatically preserve the original image file, and also saves the list of edit changes, so every edit can be a clean start, each time automatically reprocessing from the starting original pristine image file, automatically making the same previous changes. Except any new changes simply first edits the list of changes, so there is only one final state, which does not shift the image back and forth repeatedly. And then it writes the one final High quality JPG file, one time as JPG. This JPG is then an expendable copy, future edits simply discard it and start over from the pristine raw file again. This is called “Lossless editing”. We’ve come a long way, baby.
In the case of shooting JPGs, it does seem wise to always stick with the best Quality in the camera just in case, and make decisions later, because you cannot go back. But digital cameras do have options for two very different ways to create smaller JPG files. One way is to actually resample the pixels, to create actually smaller images, fewer pixels, of smaller image dimensions. These image size menu choices are usually named Large, Medium, Small. The image dimensions (pixels) become smaller, fewer megapixels.
And for any of these selected image sizes, then there are different JPG Quality menus. Nikon calls them Fine, Normal, Basic, and Canon holds it at Fine and Normal, which are JPG file compression choices. The only purpose of these JPG Quality choices is to create smaller file size of lower image quality (of still the same selected image size). The better the JPG quality choice, the larger the file (which is a good thing). Less JPG quality is a smaller file (of lower image quality). The camera's default is Large and Fine, which is the biggest image of best quality, the most versatile for the widest use, and very highly recommended. You cannot change your mind for a better quality image after you have already taken the picture. Maybe if you are certain you won't ever consider cropping or printing them, maybe only then maybe consider Medium size, maybe. But do keep Fine Quality. You can buy a Western Digital 2 TB USB 3.0 external disk drive for $60 at Amazon. There is no good excuse to skimp on image quality for file size.
Consider a 24 megapixel image (to have a number). In these RGB images, there are three bytes (JPG is 24-bit color) of red, green, blue data for every pixel, so this one is 24 million pixels x 3 bytes RGB per pixel = 72 million bytes (uncompressed, open in computer memory). That is simply how large this RGB data is, 24 megapixels and 72 million bytes, which is about 68 MB.
Digital terms are: Image size, Data size, File size, and Print size. See a review primer.
When stored in the JPG file, camera JPG Fine Quality compression squeezes this Large 68 MB data down to about 12 MB file size (cameras can vary, this is from the Nikon D5200 manual, page 241, at Memory Card Capacity). This is an average size, JPG compression varies some with individual image detail content (more below).
Anyway, this Fine Quality JPG compression reduces this 24 megapixel JPG file size to be 12MB/68MB = 18% of original uncompressed data size. This is a drastic file size reduction, but Fine Quality is usually still considered an acceptable quality for average good-enough JPG quality.
The camera JPG compression named Normal Quality squeezes the file down to 6 MB, which is 6MB/68MB = 9% of original size. This is pretty small, sub-normal really, it has had the dickens squeezed out of it, and the image quality suffers more. Some people apparently don't care, but it depends on how critical your use. And this same Large image as camera Basic Quality is 3MB, or 4% original data size. This is for when storage or transmission concerns are obviously greater than concerns about the image quality we actually have to look at. There is a little of it left, but a bigger JPG file is better quality, and smaller is ... not.
The quality losses of JPG artifacts depends on degree of JPG compression, which is about JPG file size. But before we get into artifacts, this...
About JPG file size: Do realize that the degree of JPG compression varies with the saving program, and varies with the JPG Quality factor selected, and also varies with the compression of individual image scene detail.
To see this compression size difference, sort your camera memory card, or a disk folder of several dozen of your camera images, by file size, which contains many varied JPG image scenes, but all of same original image size and size settings (To do this sort, click the word SIZE in the header of the directory listing of the files. Clicking again reverses the sort order). The Maximum and Minimum size of these varied files will vary probably at least over a 2:1 size range (possibly much more, depending on any extreme scene content). Large blank featureless areas, like sky and walls (many adjacent pixels of the same color), compress much smaller than very detailed areas, like a tree full of leaves. The file size at the midpoint of this list of several dozen JPG files (all the same image size and all written with the same JPG Quality) is more likely the typical JPG compression size, but JPG file sizes also vary with scene content.
For an example, here are four JPG images, all are the same size in pixels, all are the same high JPG Quality setting, but they are NOT all the same file size. All are 450x300 pixels image size, but using the same high JPG Quality setting varies from 2.9:1 to 21:1 compression ratio in the JPG file size. They have large JPG file size differences (up to more than 7x file size here) due to scene detail.
So... image detail level has effect, and JPG file size reduction is not necessarily a meaningful measure of JPG image quality.
These four images are all 450x300 pixels, or 135,000 pixels, x RGB 3 bytes per pixel is 390,000 data bytes (380.8 KB) when open and uncompressed. All four are the same 450x300 pixel image size and all are the same High JPG Quality level here, but the file size varies due to varying image detail which affects compression efficiency. Bland smooth featureless image areas cause smaller files, heavily detailed images are larger files. These do not have any EXIF data in them now, which could have added maybe 35 KB to file size.
That said (different scenes vary in file size, and programs vary too, making file size difficult to discuss), but speaking very generally, and barring extremes, an "average" JPG file size ought to be at least 10% of the data size to be "decent", but 20% is better quality (we should like higher quality.) I'd suggest Adobe JPG Quality 9 (of 10) for your good stuff, and let the file size be what it will. I would consider High Quality as being 20% of data size (assuming an average of many scene situations, but uncompressed 24-bit data size is always three bytes per pixel). Repeated JPG saves are bad news, and if you ever saved it ONCE at lower quality, then lower is the best you've got now. The larger you can make the JPG file, the better quality the image will be (and the largest JPG is still tiny, compared to the size of the data).
Another factor, excessive sharpening is another factor that can aggravate the JPG artifacts around sharp edges. If you want the smallest file with less artifacts, blur it a slight unperceivable amount before saving it (to soften the sharp edges). Routine sharpening enhances detail, and can make the JPG file a little larger, and JPG artifacts worse.
JPG Quality 10 (of 10) is pretty good indeed, but it is still JPG. JPG is used where small file size is more important than absolute image quality, like web pages or email, or small memory cards. Conversely, if absolute image quality is important, why consider JPG at all? JPG Quality 8 (of 10) may be "good enough" for most casual "viewing" uses, EXCEPT there is always the distinction that JPG is not good for editing, involving saving repeated times — which accumulates and compounds the JPG artifacts each time saved as JPG. Your images are either important or not, and maybe absolute quality is not your biggest concern, but if we take liberties, experience knows the time will always come when it will matter. We cannot undo JPG damage. One way to avoid repeated JPG Saves is to keep saving the image as lossless TIF or PNG until the one last final save as High Quality JPG. Or Raw images are the easy way to avoid all but the final High Quality JPG Save, with other advantages too.
There are always ifs and buts, difficult to quantify. There are lossless methods to rotate or flip JPG images, rearranging and rotating the 8x8 pixel blocks without uncompressing and recompressing (IrfanView plugins offers this), so there are no additional losses in those special lossless cases. Applications like Photoshop take heroic pains to try not to recompress image areas with no change (when possible, still has to be the same Quality level too). But bottom line, saving JPG again is a little like Russian Roulette — every time may not get you, but there certainly are risks, and when it does bite us, it always seems at the worst possible time, on the most important image. It seems wise to always preserve your original image file (it's the only way to ever get it back).
Some people really never notice much difference, so then about anything is "good enough" (until it bites them bad, the only copy of their prized image is now full of JPG artifacts — from repeated edits and saves, and/or due to specifying a Quality factor too low). It cannot be undone. There are other more critical photographers (we all probably have been bitten before, once, at first) learning that even the very best quality is barely sufficient for THEIR images. We cannot reason with either group. 😊 Certainly we cannot have the same discussion with both.
Speaking of the accumulated damage that repeated JPG saves can do, NEVER overwrite your original image file. Always preserve the unchanged original file, and save any JPG copies only to a new file. The risk depends on how important your images are, and maybe there are times and places for both approaches, but I lean towards caution. Photography is too much time and money invested trying for greater quality, so I really don't see any reason to intentionally select less than maximum quality. $60 for a huge external disk is nothing compared to the (tens of) thousands of dollars of photo gear (definitely plan on disk backup too, two copies of originals). Not to mention travel costs to the destinations. Certainly there may be a few exceptions, but regarding my more important images, I'm not interested in any debate at all about how little it might hurt. Why accept any risk? Internet transmission speed certainly is a size consideration, but which does not involve any of my archived master copies. Today, inexpensive disk space rules out any reason to compromise my image quality, certainly not my original copies. Indeed, there are better ways to go about it. Shooting RAW has many quality advantages, not the least of which is always preserving the original image, and saving any editing corrections too, and another is no JPG artifacts until the one last final save as high quality JPG.
The next images below (a small crop from a snapshot on a cruise ship) are saved six times with JPG compression varying from 20 to 100 JPG Quality, and also one PNG (lossless compression). TIF would look the same as PNG (both are lossless), but browsers typically don't show TIF files. The JPG files were saved with the free IrfanView 4.33 menu File - Save AS - JPG (I've looked at 4.54 too, and found no difference with respect to JPG). IMO, the free FastStone editor gives same JPG results and sizes, no differences I can notice, guessing that they may possibly share the same code library. However, the Quality numbers are not absolute or unique, and since there are several parameters involved with JPG compression, different programs will use different option parameters. The details are not just a single number, so the same numerical value is not necessarily the same exact effect in different programs. The IrfanView editor JPG Quality runs 1..100, but Adobe Photoshop has two scales, 0..12 in Save As, and another 0..100 in Save For Web, which seems a bit more conservative, seemingly different itself. Generally if using JPG for your good photo images, do start at a high value, like Quality 9 or 90.
FastStone and IrfanView both call themselves Image Viewers, both are free and worthwhile viewers, and they also edit images. IrfanView seems a perfect viewer for looking through a folder of many images. FastStone seems the more complete and versatile editor, because it has Levels (a really big thing) and the Curve (which more should use). But FWIW, what I actually use is Adobe Camera Raw (ACR) and Photoshop.
To understand JPG losses, we must learn to recognize JPG artifacts. There are a couple of types of JPG artifacts. One type is 8x8 pixel blocks seen in smooth featureless areas (pixels made to be the same one color in the block, which compresses better). Modern programs seem to do that a little better on those today. Another is harsh artifacts (like spotted fuzz) around sharp edges. These artifacts are seen because those pixels now have different color values, not true color values. Viewing larger, like at 3x actual size helps to learn to see JPG artifacts (shown further below as 3x larger if your screen is at least 900 pixels wide). JPG artifacts are real, regardless if you are aware or not, and you will want to become aware.
This image is a small 300x300 pixel 100% crop (actual size) from a 4288x2848 12-megapixel RAW image (Nikon D300). All are identical copies of the same one pristine image (from RAW and PNG, it had never seen JPG before), just with different text and JPG compression added. A PNG image is added for comparison, because PNG uses lossless compression, no JPG artifacts. And browsers can show PNG, however even when awesomely compressed, the PNG is still a file seriously larger than JPG (so one point is that even a JPG large enough to be decent and good is still smaller than other types of files). JPG artifacts seem harder on the sharp edges of graphics, so if interested, be sure to see the 3x enlarged added graphic text characters.
File sizes: The images are two sets, saved by IrfanView and by Photoshop. Each of those sets are shown 300x300 pixel actual size, and again, the same smaller files but enlarged 3x to 900x900 pixels (which enlargement causes slight blurring). There are options when creating JPG, and different programs can use different options or libraries that can do it a little differently. And Photoshop wisely seems a bit conservative in this regard. When comparing file sizes, note that the image EXIF data can be maybe 30 KB size. Therefore, all of these small files have no EXIF data in them, to allow JPG size comparison. The uncompressed size of all is 300x300 x3 bytes per pixel, or 270,000 bytes.
File sizes for this image here (IrfanView version):
TIF LZW - 184 KB - 70% - Impressive lossless reduction
PNG 24 - 144 KB - 55% - Amazing lossless size reduction
JPG 100 - 77 KB - 29% - Awesome size reduction, but lossy
JPG 90 - 29 KB - 11% - Average or common usage, lossy
JPG 80 - 21 KB - 8% - Losses becoming more apparent
JPG 60 - 14 KB - 5% - not much question now
JPG 40 - 11 KB - 4% - poor
JPG 20 - 8 KB - 3% - pathetic
However, these JPG Quality values are not absolute numbers, and Quality 100 may be hard to fault, but it does NOT mean 100% Quality, it is always still JPG. Photoshop shows better quality on the same image at same quality setting, because it is more conservatively making larger files, often about twice as large (because it's important, whether we may realize it or not). The JPG Quality numbers (like 8 of 10) are entirely arbitrary, different programs do it their own way. And you can choose higher quality too.
The image degree of detail also affects JPG compression size (see above).
I'd suggest experimenting in the photo editor you use, on several very different images, and with careful study at enlarged viewing, find the JPG Quality setting that always seems very adequate (artifacts difficult to detect). And then in that program, I'd always use at least the next better setting for anything important. And start by setting your camera's JPG Quality setting to its highest value. Why not? Low quality cannot be undone.
Most of the images above may look decent enough at first glance when seen small, but these repeated next below are the SAME 14 files again, exactly the same small image files above are simply shown below a second time from your browser's cache (not a copy, but the same exact image files), but now with browser instructions to enlarge them 3x for a better look at the artifacts (this interpolation is necessarily somewhat of a blurring operation (3x enlargement reduces resolution to 1/3), but all suffer the same).
Starting off at JPG compression 20, you can easily see the blocks in smooth areas, and the false fringing around sharp edges. These are two types of JPG artifacts (due to JPG compression, and which are not a good thing). This is the meaning of JPG losses... quality losses. All of the detail we see in images is color variations of the pixels. Artifacts cause a different distorted color (to be visible), which is image quality losses.
JPG compression usually affects the sharp edges of graphics worst than photo detail, at least more noticeable in graphics. Here for example, the added text characters around the label "JPG 60", or even "JPG 80" (in the enlarged version). The same effect is on all the sharp edges. That is unnecessary, solved simply by increasing to a more reasonable compression level, and it will still be much smaller than the TIF or PNG lossless compression.
You really do need to learn to recognize JPG artifacts. Enlargement is the best way to evaluate your JPG artifacts, so you can see their details, to see what they do. These next sets of images below do that, being the exact same image files as above, but are enlarged here 3x, to 900x900 pixels, if your screen is that large. They are large, but showing them is pretty much the entire point. They are the same image files as just shown (just enlarged when repeated), so there is no additional download involved. Enlarging them 3x is a moderate blurring operation (less resolution), but the artifacts are more clearly identified.
Check here to Show the SAME 14 images above enlarged greatly, 3x
or Uncheck to Hide them again.
Recommended, so you don't miss it: The evidence of JPG artifacts is seen this way.
They may be a bit large for a cell phone (3x, 900x900 pixels),
but a larger screen should handle them.
The JPG Quality numbers are an arbitrary scale. JPG Quality 8 is NOT an absolute value of quality. Different programs choose different parameters, and call it what they want. JPG Quality 100 is NOT a percentage or a maximum, it is still a JPG file. We do tend to blindly say that JPG Quality 8 or 9 are reasonably good for many uses, but you ought to evaluate what your program does. For example, the numerical JPG Quality levels (0..100) of Photoshop CS6 menu File - Save for Web (which is now at Photoshop CC menu File - Export) are very conservative (calling 80 as being Very High Quality), preserving better image quality (with significantly larger files with less JPG artifacts) than the corresponding numerical levels at Photoshop File - Save As - JPG (calling 8 as High Quality, which is 0..10 scale.) And in Irfanview, JPG Quality 80 is nearly good, but there is evidence of artifacts around sharp edges, and 90 is better.
These are how the images came out of the JPG files (but enlarged now, by interpolation, to recognize the JPG artifacts easier). All were the same one original image before compression and going into the files. The differences (between what we put in, and what we get out), is called "losses", due to JPG artifacts caused by lossy compression. Lossless compression has the obligation that every pixel come back out of the file exactly as it went in. Lossy compression allows the process to change the data a little (the RGB data is the color of each pixel) to make compression more effective, simply ignoring difficult details. The file can become quite small that way. There are diminishing differences with higher Quality, but the PNG just looks sort of "pure" (lossless). The added text is all the same identical operation for all, but lossless PNG just comes out more pure. In contrast, lossless compression cannot be as effective making a tiny file, because it must honor higher standards, and absolutely ensure no pixel color value is altered in any way — what comes out of the file is an exact copy of the data that went into the file.
The examples above show what is meant by JPG losses. It is about losses of quality — meaning, the pixels that come out of the file are simply not as good to look at as the pixels that went into the file. The image still has the same count of pixels, and the size is still three bytes per pixel when opened again, etc, but now some pixels have altered colors, called JPG artifacts... like dirty pixels, which is quality losses. Remember, artifacts continue to accumulate, getting worse, every time you edit and Save the file as JPG again. Each Save is lossy compression again. And this loss is not repairable, so be aware, don't do this repeated times. There are better plans.
Make no mistake - JPG 100 is NOT 100%, It is Not a percentage of anything. It is always still JPG, and JPG Quality 100 is NOT a perfect copy. Above is the pixel differences in the original IrfanView JPG 100 image and the PNG image, as shown by the Adobe Photoshop CS5 Calculations tool, when comparing only the blue channels (red channels look essentially the same as this, but the green channels are pretty dark in this one). This is enlarged near 2x, but is shown at default brightness, the actual difference, no fudged adjustments. Seems to me the differences are in the anti-aliasing on the edges of objects (almost like a line drawing). These were all the same image with the same pixels, until compression, so my notion is that JPG apparently didn't consider saving all of these infrequent colors as important. IrfanView has a menu (Images - Information) that counts colors in images, and it reports the PNG image has 35,046 colors, and the JPG 100 image has 23,368 colors (only 2/3 as many now.) There is more color count in the lower JPG values, which are the artifacts probably. Photoshop JPG does the same reduction of colors, in about the same degree. The JPG 100 file, when saved again now as PNG, is nearly 5% smaller than the original PNG file, because its modified data is easier to compress now. JPG 100 is a relative number, it does NOT mean 100%, and it is NOT lossless (but yes, 100 is still pretty good).
If you start your comparisons from an original JPG image, you may not see this much difference remaining (you have no base of reference then), but the image here started out as RAW, it had never seen JPG before. This may be minor visually, but there is no way we can argue that they are still identical images. We might argue "good enough", and Quality 90 probably is good enough (few artifacts still very visible). However, if this is the master copy of our prize image, we may not be willing to consider any argument at all about quality. But JPG Quality 100 is pretty good, and the file sure is small. I would have no concern about sending the JPG 90 or 100 images out to be printed (printers skip over small details too), but not to keep as my archived master copy, which might be edited or resampled again. The actual worry is about creating more differences next time it is saved as JPG. JPG artifacts accumulate at every Save as JPG (compressed again at every Save).
The only point here is that even JPG Quality 100 is definitely always still JPG, and it is never going to be lossless compression. In contrast, lossless means every pixel's data value (color) comes back out of the file exactly the same as what when in - no artifacts. That's always a good thing, if quality is a major concern. If you have read this far, I assume you are concerned about image quality.
Speaking on a 1..10 scale (Adobe), JPG Quality 5 might sometimes be "good enough" for some unimportant web page images. We could debate it, but Quality 9 will print OK, but may Not be good enough to archive your prized best pictures, at least not for mine. At bare minimum, for your good stuff, 1) you should always use a high value of JPG Quality, if not 10, at least 9. My notion is that a High Quality JPG is maybe 1/4 to 1/3 of uncompressed size. And 10% of uncompressed size is usually a usable decent copy. And 2) you should minimize any occurrence of additional Saves as JPG (each Save compresses again, and losses accumulate). When emailing pictures of the kids to Grandma, sure, resample a small copy for video, and JPG 8 is good enough for email. That is an expendable copy, but your master archive copy should be the good stuff.
For those who critically care about their images, the best plan, and actually, the easy way, is first, to always keep and archive your unedited original image as the best master you will ever have. Otherwise, you can never get it back, so never write over it — always keep that original intact for just in case (whatever it is, especially if it is a JPG from the camera — and the camera should be set to create the finest possible image it can.)
Then second, when editing (saving only to a copy with a different file name, always preserving the original intact), always save your in-work image ONLY to a lossless format (TIF or PNG), EVERY time, UNTIL your last necessary FINAL one JPG save (at high quality level). For example, Photoshop, and the free editors IrfanView and FastStone (see Google), have batch modes to copy many files from JPG to TIF in one easy operation. This would be pointless unless you are intending to edit them, because this TIF step will NOT remove any existing JPG artifacts, the data will still contain those original JPG artifacts — but subsequent TIF Saves will not add any more. Computers and disks are big and fast and inexpensive today, this larger file size is a small issue today (and that is in fact simply how big your data is). Then as lossless TIF files, you can edit away, red eye and color and contrast adjustments, straightening and cropping and resampling, and saving again with wild abandon (just NOT as JPG), until finished, at that needed One Final JPG Save. So if it was JPG previously, now the total is only two saves as JPG (original camera save, and this one final save, is two), which is worse than one, but much better than six. Using camera RAW images would also eliminate the first JPG, and offer other advantages too.
And then third, when if any further need to edit it again comes up (resample size, whatever, anything requiring another Save As JPG), discard this second JPG (as an expendable copy), and start over from your better archived master you kept. Avoid using any image saved repeated times as JPG. JPG is lossy, which means we do not get back the same quality we put in. There are more losses every time it is saved as JPG. With lossless formats (PNG or TIF LZW), it does not matter if you save a jillion times. But it matters if saving to JPG. An extra unthinking save as JPG is never a good plan. And if it overwrites your only original copy, it is a terrible plan, you can never get it back.
Batch processing: Speaking of the philosophy of expendable JPG, and assuming you keep a high quality lossless archive, then there are easy ways to run off batches of expendable JPG for one-use viewing, temporary JPG copies sized for monitor viewing, or for HDTV viewing, or to upload to be printed, etc. Several programs have batch modes to do this.
Adobe Photoshop has its menu File - Scripts - Image Processor. It can read Camera RAW images, including their previous processing instructions (White Balance, Exposure, Cropping, etc). Also can apply other Actions as it goes.
The free FastStone editor has its menu Tools - Batch Convert Selected Images.
The free IrfanView editor has its menu Files - Batch Conversion/Rename.
I use Photoshop Raw, but of these two free programs, IMO, FastStone is the better editor (more conventional and complete, specifically with Levels), but I like IrfanView as the convenient viewer (less cluttered).
Here is the trick for batch resampling: We always must resample using "Preserve Aspect Ratio", so generally, if you want a batch of say 1800x1200 pixel size (to print 6x4 inches), you can specify the larger target dimension twice, 1800x1800, and then regardless if the batch contains mixed landscape or portrait shapes, the largest dimension will be 1800, as appropriate. This works for batches, and Aspect ratio controls the smaller dimension, which can be however you prepared it.
Or the Photoshop batch has its Resize to Fit option, and the FastStone batch has its Switch Width with Height option to do this same trick more overtly. Computer speed today makes it trivial to just run off whatever size you want at the moment, and then discard those expendable JPG after that one use. You always have your high quality lossless archive copy, and can do this at will.