Differences between JPEG and RAW files:
To understand how the histogram affects both file formats, you need to know how the files are structured.
Generally speaking, JPEG files are finished images. While RAW files are raw data of the photo. These "digital negatives" still have to be processed / converted with a RAW converter. You can't display / view a RAW file itself.
The cameras generate a small JPEG version of RAW files for preview. And image processing programs such as Lightroom or Photoshop also generate a JPEG as a preview.
And what does all this have to do with the histogram?
With a JPEG file, the image information has already been edited. Cameras that take pictures in JPEG format process the images internally without the user noticing anything about it.
So the photos are "finished", so to speak. And also the histogram resulting from the image is "finished". Thus the photo offers very little reserves if you want to edit it later.
For example, if the photo is too dark and you want to lighten it up, you get noise and the quality drops rapidly.
The situation is completely different with RAW files. These raw data provide sufficient reserves. As mentioned above, RAW files are not yet developed. The information is stored with up to 16 bits per pixel, depending on the camera model. Simply put, the way the light falls on the camera's sensor. First software on the computer or in the camera creates an image from it.
A RAW file therefore requires much more storage space than a finished JPEG image. But it contains all the information in the RAW file and therefore a lot of reserves to edit the image.
You can say that if the histogram is truncated from a RAW file on one side, you still have enough room for corrections when editing the image. Usually these are one or two f-stops.