Sometimes, you may need to access the memory of a cv::Mat or an IplImage directly. If the image contains M channels, then it becomes important to know how the pixels of these M channels are stored in the image memory. According to OpenCV documentation here:
The M bytes of every pixel are stored together.
For 3 channel image, the RGB channels are stored in BGR order. There is no particular reason for this, OpenCV just happens to store it in this order. It may be due to influence from Windows, where most internal APIs seem to deal with this channel order.