I spent forever experimenting on getting a realistic volume atmosphere for a gas giant. My method will be explained step by step below.
** UPDATE **
While simplifying the node setup (easier to remember and faster renders), I discovered that the color ramp does nothing. Screenshots added.
1: To get a realistic density gradient and to have the edges of the atmosphere taper, you will need to connect the Object output to a Mapping node, and set that to point.
2: The scaling of that mapping node has to be the square root of the atmosphere sphere's size (in the sample scene, the sphere was 10 units, so the scaling was left at 1) or else the volume will go beyond the edges of the object. The result is a volume material that is smaller than the edges of the object.
3: Connect the mapping vector to the gradient texture node, and set that to spherical. Connect the Fac output to a multiply node.
4: The Multiply node needs to multiply the input by the square of the object's radius (which would be 10 in this example) x 10-100 (depending on how thick you want your atmosphere), and that the Multiply node in turn needs to be connected to both volume nodes.
6: Rayleigh scattering is easily emulated by using a combination of Scatter and Absorb nodes. Absorb has to have blue at 0.995, green at 0.088 and red at 0.024 (corresponding with the extinction coefficient of water; Neptune and Jupiter type planets have water and ammonia clouds and ices in them) and Scatter has to have Red at 0.224 Green at 454 and Blue at 0.950 (corresponding to the scattering probabilities of Lord Rayleigh). Absorb needs to go to the bottom input of the Mix Shader (before the one that controls density) and Scatter needs to go to the top one. The Mix Shader's Fac value should equal the albedo you want, which is 0.27 for Neptune and roughly the same for Earth. A rocky planet's atmosphere will not need the absorb node. Anisotropy for the scatter should be 0.250 to get the edge brightening that comes from peering through the atmosphere at a grazing angle.
7: For a rocky planet's atmosphere, it is helpful to simulate haze from dust. Add an addition scatter node and an extra mix shader. The different types of dust has different optical properties, so you will have to experiment. The new scatter node should plug into the top input of the mix shader and be no more than a few percent of the overall mix.