When you export a picture to JPG you can normally choose its quality in a 1-100 scale. I like to keep a good quality but it wouldn't make sense to keep a JPG that will be almost as big as the original RAW, so is there any guideline to select a particular JPG quality for particular uses? I am mostly interested in Internet sharing and ordering prints online.
To be frank, it is entirely anecdotal that a JPEG image should be exported at a certain compression level all the time. The amount of JPEG compression should really depend on the usage purpose for the JPEG, and the contents of the JPEG.
The quality level one should choose when exporting an image to JPEG is highly dependent upon the kind of detail contained within the image. An image of a smooth blue sky or a sunset sky with large areas of orange gradient should probably use a high quality setting, 90-100. An image that contains nothing but complex detail could probably get away with a quality setting of 50-60, possibly even lower. There is no single "best" JPEG compression setting, and depending on the type and complexity of detail (or lack of complexity and detail), you may find yourself using 40-60, 70-80, or 90-100 as appropriate for the photo(s) you are exporting.
An excellent visual resource for how JPEG compression affects IQ can be found here:
This site demonstrates JPEG compression from the lowest to highest settings in discrete ranges for a series of sample images of differing content. You can clearly see, by observing each image at each compression level, why a higher setting such as 90-100 may be required in some cases, and a lower setting such as 40-60 is entirely acceptable for others.
As a side note, if you are saving a JPEG for any kind of print purpose, or for viewing on-screen at a large size (i.e. as a wallpaper for a 30" 2560x1600 screen), there is no reason not to use the best quality setting available. When saving for web, compress as much as you can without introducing visible compression artifacts. Different classes of images will regularly fall into certain JPEG compression levels (the site linked above can help learning what fall where)...so it can quickly become second nature to know what compression level to use when saving various images for the web.
Disks are still pretty cheap these days so there are advantages to JPEG files, even if they are as big as the original RAW, instant image preview, being able to display on computers without RAW software.
The "quality" parameter determines the quantization matrix used to compress the data. Without going into too much detail this determines the degree to which the frequencies contained in an image are approximated to achieve compression. The important thing to note is that there is no direct correspondence between "quality" and final size.
Therefore quality merely determines what proportion of image information will be lost, if an image that contains more information to begin with (in terms of high frequency details) you will get a larger JPEG file even with the same quality settings. There is therefore no global setting you can use, if you want files of a certain size you have to tune the quality for each image.
Alternatively you might want to use a higher setting for images with more fine detail (or noise - noise doesn't compress well so can result in more artifacts). If you are doing a one off image I would use any program that gave you a preview of the compressed image (Photoshop does this) and play with the value until you get the quality you want at a size that is reasonable.
I never archive in JPEG format, I always keep the original RAWs, so any time I'm producing a JPEG it is for display on screen. I used to start with quality 7 (out of 12) in Photoshop, unless I noticed artifacts, then I would increase it. Then I moved to 9/12 as my default quality. As internet connections speeds and storage increased much faster than screen resolutions, these days I just use 11 (one step down from maximum, there's a bit of a jump in size when you select 12) all the time and don't worry about it.
When sending images to print, if they have to be JPEGs I use the highest quality I can unless the print company complains. You've worked hard on an image, there's no sense reducing the quality to cut upload times by a few minutes.
Use 90, or preferably 95. In my experience, the size gain when using anything under 90 is in most cases no longer beneficial in relation to perceivable quality loss, and should only be used on very specific images that can profit from JPEG compression and/or need to stay under a maximum file size (e.g. images used when building a website).
JPEG compression lower than about 75 will definitely show visible artifacts.
What Matt said, but I want to add that JPEG actually has two compression schemes built in. The first is based on a discrete cosine, which allows certain frequency components of the image to be thrown out. This is the lossy compression with the "quality" parameter that can trade off compression with fidelity. At maximum quality, this compression scheme is mostly eliminated.
JPEG also uses huffman encoding for additional compression. That is a lossless scheme, so it is always there without any need to control it.
So even at maximum "quality", JPEG will have some useful compression. I just looked at sizes of one example image of a ordinary scene for comparison. The Nikon NEF raw file is 26 Mb, which contains 14 bits/pixel and is uncompressed. My post-processed JPEG version saved at maximum quality is 9.1 Mb. This contains 24 bits/pixel, although of course some information is lost and other information interpolated from values in the original raw image. This same post-processed image converted to a TIFF file with LZW and forward differencing compression (both lossless) resulted in 20.3 Mb.
As a final experiment, I copied the 9.1 Mb post-processed file and the TIFF file resulting from it both to JPEG files with maximum quality setting. Both resulting JPEG files are exactly the same size to the byte of about 8.5 Mb. This shows that even at maximum quality, just a little lossy compression is going on, but not much. It also proves the point that no information was lost at all going to the TIFF file.
As Matt does, I archive the original RAW files from the camera. I also archive my general purpose post-processed version as JPEG with maximum quality. Even pixel peeping at high contrast and sharp edges doesn't reveal compression artifacts to the human eyeball. I like having the post-processed picture in JPEG form because its probably the most immediately usable format. If there is a issue and I want something different, I've always got the raw file to re-derive a another post-processed version from with different tradeoffs.
I used to use 80 as the default quality level of my JPEG images (my software has 0-100 for its quality range), but lately I've been using 100 as default unless there is a specific need for a smaller file size. There usually isn't. I have gone so far as changing the default for the JPG image driver in the source code so that I don't have to keep specifying the quality level most of the time. It's not like the old days where a Gb was a lot of memory. (Actually, I'm old enough to remember when 1 Mb was a decent amount of disk space, but back then we weren't doing digital photography either).
I keep my jpeg quality slider at 100% for my "developments", and will so I lose less detail before the online site will recompress it anyway. If I put it on my own site through ftp I might choose 90% and supply a thumbnail. 80% of online people watching photos online has a fast DSL anyway.
Here is a test with quality from left to right: 10,20,30,40,55,70,80,90,100% I show crops from each file.
File sizes for the full files are: 210k, 278k, 347k, 477k, 601k, 709k, 987k, 1.7M, 7M.
The raw file was 8M but remember that is basically a monochrome image and a smaller thumbnail plus a little meta data. The BMP is 30.5Mb!
To me the difference from 100 to 90 is noticeable but very small. But I would never go under 100% if there is a chance I might want to open it and process it further. below 100% is a "process time EVER" deal.
From 90 to 80 the difference is bigger, and 70% starts to look like crap. So my conclusion is: for backup and possible reopening 100% if you need to save some space/upload/DL time and it wont get repacked: 80-90%.
To get the best possible compromise between compression and quality you would have to try each image with different compressions to see where the quality is acceptable. If you don't want to do that to every image, you can try out a few images and then go with that compression level, and accept that the level is close enough.
As a starting point:
What to look for, to spot JPEG compression artifacts: