RGB is not a color space, it is a color mode or color model. The same for HSB, HSL CMYK, Lab, Grayscale.
But if an image is in HSL color space, is computer will save Hue, Saturation, Intensity
And how computer know what color space an image is?
Because you tell it what you need to tell it.
On the beginning of each photo file, or any file for that matter, there is a set of instructions on what is the content of the file and how to interpret it.
A color space
Is what colors of the perceptible human vision can be stored, and reproduced by a device.
In that respect Lab is a color space, as well as a color mode.
A basic explanation on what is the difference
Between color mode, color model, and color space.
Color mode is the way you store color information. For example RGB stores Red, Green, Blue info.
Color model is the theoretical base of that, is which 3D coordinate system you will use. A RGB model uses rectangular coordinates, like a cube.
A HSB and HSL model uses polar coordinates. Hue is not a range between 0-255 but a 0 to 360 value (a circle), the 3D shape is more like a conical one and two inverted cones for the second (also can be interpreted as a cylinder, but I personally do not like the cylinder shape).
Color space is how to interpret the previous values.
My typical example: grab a water based happy marker, a cyan one.
If you use it on a newspaper the color reproduced will be dark, but on a coated glossy paper will be a light cyan.
The Cyan value is the same: Just full ink on a stroke, but the color space of the combination is totally different. One can only reproduce dark colors, the other one has a wider range of reproducible colors.
And a fourth concept a color profile is a small set of instructions on how to convert-reproduce-display-correct thoose kind of diferences depending on the medium.