Please allow me to hijack this thread to explain why there is even a need for a variable "gain" value.
Lets first look at how light gets turned into a number.
The photoelectric effect (what Einstein received his Nobel prize for) is the process where a photon is turned into an electron (when electrons are created this way, they are often called a "photelectron," the "e-" that you see in camera specs). The "quantum efficiency" expresses the amount of energy released as photoelectrons, per energy from the photon.
Each electron carries a charge. When a charge moves, it creates an electrical current. Electrons don't really travel along a wire; they kind of bump the next electron down the line. When you push an electron into one end of a wire, an electron pops out the other end of the wire -- but it is not the same electron :-). From the macroscopic viewpoint (at least for a lowly engineer like myself), it is as if the electron has traveled to the other end of the wire.
You can then convert this current into a voltage. For example, using a current node of an operational amplifier (op-amp).
Once you have a voltage, you can apply the voltage to an Analog-to-Digital converter (abberviated as A/D or ADC) that convert the voltage into a number. The numbers are called Analog-Digital Units (ADU). This is the "ADU" that you see in histograms, etc.
ADCs today are mostly binary. So the ADC could be an 8 bit ADC, 12 bit ADC, 16 bit ADC, etc.
An 8 bit ADC would produce a maximum of 256 (28) ADUs, and a 16 bit ADC would produce a maximum of 65,536 (216) ADUs.
So, you start from a photon, and you end up with ADUs.
Notice that the ADC will quantize the input signal into integers, while the input signal is a continuous analog voltage. Engineers have no problem representing a real valued number as an integer number, but it probably gives a mathematician heartburn representing a real number as a cardinal number :-).
There is therefore an unavoidable "quantization noise" introduced in the A/D process. I.e., the output ADU does not represent the voltages perfectly. (Statistically this noise has uniform probability distribution.)
You can have ADU=54, or ADU=55, but you cannot have ADU=54.35 for example.
When the input voltage fluctuation is small, this quantization noise can be relatively large, and thus degrade the signal-to-noise ratio (SNR). When I was studying RF modems, I found that if the input analog noise is 10 dB higher than the quantization noise, the SNR is only degraded by 0.1 dB.
0.1 dB loss of SNR is negligible, so we can pretty much say that the quantization noise becomes a non-issue when the input analog noise is 10 dB greater than it. The input analog noise consists of shot noise from sky background, dark current noise from the sensor, pattern noise from the sensor, read noise, input noise of the A/D converter, etc.
Here comes the rub: sky background and sensor dark current noise are both very low when you use short exposures. So, for such cases, you want to amplify the analog voltage by a larger gain before handing it to the ADC, so that the quantization noise does not become a problem.
On the other hand, when you use long exposures, the sky background and camera dark current noise can be quite large comared to quantization noise of the ADC. Additional gain will not practically improve the SNR of the image. And you just lose dynamic range when you use higher gains.
So, there you go, a simple explantion of camera "gain," and when to use it and when not to.
Chen