Before doing any of that though, if you want a huge improvement in sound quality for little money and little work no matter if you're on headphones or speakers, simply:
Make sure you have a decent sound card (also called audio interface or DAC - digital to analog converter) if you are on a PC. Newer Apple computers seem to have ok DAC's although I'm not too sure about mobile devices. The thing about mobile devices though is that they are much harder to find audio interfaces for, especially if they aren't Apple/iOS devices, and obviously it will likely ruin the portability of your "mobile" device.
But yea for example something like this would be high quality and work with iOS or Mac even:
Or a more regular interface for your laptop or desktop:
You will also typically gain not just quality audio outputs, but quality audio inputs going into your computer as well if you're into recording things. If you buy one of these but your headphones only have the baby 3.5mm jack, you will need a 1/4 inch adapter like this as audio interfaces/external DAC's typically have 1/4 inch plugs: https://www.monoprice.com/product?p_id=7139
This one is even more crucial for decent sound quality in our era of only consuming compressed (degraded quality from the original recording) media en masse, and that is to download or listen to your music in high quality formats (AIFF or WAV, and maybe 320 kbps MP3 if you must) which typically requires you to pay whether it's a streaming service like Spotify or Apple Music (no longer iTunes apparently) or Google Music or Amazon or Beatport (Beatport offers "full quality" WAV or AIFF downloads but is geared towards djs) etc. Better yet, just buy the CD if you've got the money and simply rip the songs off of it in WAV or AIFF format (formats which both have no file compression involved and are full quality unlike MP3), both of which are also always
going to be higher quality than any MP3 or any other similarly lossy compressed audio format via this method (or via any method that involves obtaining an original uncompressed copy directly from a reseller/publisher). But even if you can't get ahold of the CD or a WAV/AIFF copy, you will still typically have much better quality compressed audio by obtaining the music directly from a reseller or even through a legit service like Spotify or Apple Music etc. compared to listening to re-uploads by random users on YouTube for instance. If you pay you will also support your favorite artists which helps them out if they are lesser known. You can also research (Google) and typically find out what formats and kbps (bit rate) these music publishers/stores offer their music in, or what format and kbps their stream will play at!