The JFIF standard requires YCbCr color space for image data. Image matrix (CMOS or CCD) usually generates image data in RGB space. The color space converter is used for translating RGB to YCbCr space.
The RGB color space includes three components related directly to red, green and blue elements of color. We are able to get any color palette by changing the value of each primary color. Maximum value of each primary color gives a white color and the minimum value of each pimary color gives a black one. The figure below shows famous "Lena" picture in RGB decomposition.
Because of mutual redundancy between components, RGB is not efficient for storing image data. YCbCr is a practical approximation to color processing and perceptual uniformity, where the primary colors corresponding roughly to Red, Green and Blue are processed into perceptually meaningful information. By doing this, subsequent image/video processing, transmission and storage can do operations and introduce errors in perceptually meaningful ways. In the YCbCr color model the appearance of a pixel is given by its brightness (Y), its blueness (Cb) and its redness (Cr). The Y component, called luminance, is weighted sum of R, G and B components. The weight depends on human eye sensivity. The Cb and Cr components, called chrominance indicate how much blue and red respectively is in that color. The figure below shows "Lena" in YCbCr decomposition.
According to CCIR Rec.601, with little modifications for JPEG, color space conversion bases on three linear equations:
Y = 0.299 · R + 0.587 · G + 0.114 · B
Cb = -0.1687 · R - 0.3313 · G + 0.5 · B + 128
Cr = 0.5 · R - 0.4148 · G - 0.0813 · B + 128
128 is added to the chrominance components to have a value range from 0 to 255 instead of -128 to 127 (two‘s complement). Since the Discrete Cosine Transformation needs two‘s complement signed values as input data, 128 will be subtracted from all values (including Y). Most literature explains this in two steps, probably to keep the similarity to the Y, Cb and Cr values as they are defined in CCIR Rec.601.