There are many Bluetooth profiles and the one dealing with streaming music is called A2DP (Advanced Audio Distribution Profile). Handsfree headsets intended for phone calls might use the Headset (HSP) or Hands-Free (HFP) profiles but headphones intended for listening to music uses A2DP.
The A2DP profiles requires that all devices support the SBC codec (low-complexity subband codec) as a simple, fall-back codec to be used if nothing better is available.
Important to note is that any better codec has to be supported by both devices in order to be used. If you buy expensive headphones with some fancy codec that you phone does not support, then they will fall back to using SBC.
SBC is designed to provide "adequate" audio quality and require little processing power so that it is possible to build headphones without the CPU power required for more advanced codecs.
But there is nothing preventing manufacturers from using well known high quality codecs such as MP3, AAC or Atrac. Yes, the very same codecs that are used for compressed audio files. The most common high quality codec for audio over Bluetooth, however, is "aptX" that is specifically intended for this purpose.
AptX is a codec that requires a license from Qualcomm which is why not everyone has implemented support for it in their phones and headphones. Apple and Qualcomm have been involved in patent and royalty disputes for a long time and this might be the reason iPhones do not support aptX.
That's right. If you bought a pair of expensive headphones because they claimed superior sound thanks to aptX and you are using them with your iPhone... Yeah, you're probably listening to SBC audio. Some high-end headphones also lack aptX support, such as the popular Bose QS35.
AAC that we mentioned earlier is also used as a Bluetooth codec but is less common than aptX. Apple has chosen to use AAC and it is supported in both their iPhones and AirPods. But if you bought a pair of Airpods for use with your Android phone that does not support AAC over Bluetooth, then you're probably listening to SBC audio.
And then there is of course Sony who in the proud tradition of Betamax, MiniDisc and Memory Stick have decided to invent their own codec for Bluetooth audio (and it's not Atrac): LDAC. This is supported by, well, Sony.
So when you buy a pair of Bluetooth headphones, make sure both your phone and the headphones support the same high quality codec.