How shades of gray are represented in the RGB color space. If you're unfamiliar with RGB color see this tutorial first.
Shades of gray are represented the same way as other colors, as an RGB value. For example, middle gray is (128, 128, 128), pure black is (0, 0, 0) and pure white is (255, 255, 255)
In the RGB color system, shades of gray are colors in which all three channels have the same value. For example (2, 2, 2); (55, 55, 55); (119, 119, 119) etc, are all shades of gray.
This chart shows the shades of gray from (7, 7, 7) at the lower right to (255, 255, 255) at the top left. The black frame is (0, 0, 0).
Since every shade of gray has the same value for all three channels, a gray value can be expressed as a single number from 0 to 255.
A necessary step in black and white conversion is to take a color image with over 16 million potential colors and convert it into a grayscale image with only 256 shades of gray.
However, simply assigning a gray tone to every color in a photograph is not enough. If every color were assigned to a few middling shades of gray the resulting image would look pretty awful.
The best results come when the colors are converted so that the maximum range of gray tones, from the deepest shadows to the brightest highlights, is achieved.