https://www.impulseadventure.com/photo/jpeg-decoder.html
https://www.impulseadventure.com/photo/jpeg-huffman-coding.h...
Of course, there are also plenty of other "write a JPEG decoder/encoder tutorial" articles out there, of varying quality --- which if anything proves that it's not actually so hard. The standard contains a surprisingly simple and elegant flowchart description of the Huffman encoder/decoder.
The more modern JPEG 2000 encoding based on wavelets can be pushed much farther before visible artifacts appear, and includes a surprisingly efficient lossless mode. Of course, all this improvement is rather moot until common applications actually support it.
That was 12 years ago, and J2K is still pretty much unknown outside of niche applications. I'm not sure what they mean by "surprisingly efficient lossless mode", but decoding J2K is slower than regular JPEG by at least an order of magnitude if not more. The lack of articles about how to write decoders/encoders, or even just how it works in detail, is another sign of its relative obscurity. I've been studying the standard on and off for a few months, intending to write an article or even a decoder, but haven't gotten around to it yet. It is certainly an order of magnitude more complex.