Fast RFC 4648-compliant Base16 encoding

Version on this page:
LTS Haskell 22.30:1.0@rev:1
Stackage Nightly 2024-07-23:1.0@rev:1
Latest on Hackage:1.0@rev:1

See all snapshots base16 appears in

BSD-3-Clause licensed by Emily Pillmore
Maintained by [email protected]
This version can be pinned in stack with:base16-,2430

Module documentation for


Build Status Hackage

RFC 4648-compliant Base16 encoding and decoding.

For the companion optics and pattern synonyms, see base16-lens.


The following types have supported codecs:

  • Data.ByteString
  • Data.ByteString.Lazy
  • Data.ByteString.Short
  • Data.Text
  • Data.Text.Lazy
  • Data.Text.Short

Additionally this library has

  • Much better performance than base16-bytestring for encode and decode, with a more conventional api.
  • Support for mixed-case hex decoding (defaults to lower-case encoding by convention)
  • Optics for handling more complex structures with Base16 representations via the base16-lens package
  • Checks for both validity and correctness of Base16 encodings.

There are no dependencies aside from those bundled with GHC.


Revision history for base16

  • Add support for GHC 9.4
  • Added decodeBase16' to Data.ByteString.Base16* (thanks to @shlevy #20)

  • Fix incorrect behavior in Data.ByteString.Short.Base16#encodeBase16
  • Drop base GHC <8.10

  • Allow for mixed-case lenient decoding + validation
  • Bump testing for mixed-case hex

  • API for decodeBase16With has changed to require ByteString instead of Text. This is in alignment with work done on base64, which reflects the same API. This will be the final design for these types of conversions.
  • Test coverage now at 94%
  • Add NFData, Exception, and Generic instances for Base16Error + @since annotations for new instances. (#5)
  • Doc improvements and add -XTrustworty and -XSafe annotations where needed. (#5)
  • Optimized inner loop for short text and bytestrings (#4)
  • Changed encodeBase16 in ByteString.Short to produce ShortText, instead of Text.


  • Added support for Text.Short and ByteString.Short values

  • Improved performance. Decode and encode are now 3.5x-5x the next best lib.


  • Add lenient decoders
  • Fix bug in Text decodeBase16 which failed on invalid UTF-8 values as a result of decoding
  • Add decodeBase16With combinators


  • Add lazy variants for Text and ByteString values – 2020-02-17

  • Documentation now references correct RFC section

0.1.2 – 2020-02-17

  • Unmask loops - now correct.

0.1.1 – 2020-02-17

  • Mask Word32 and Word64 loops (flaky) – 2020-02-16

  • First version. Released on an unsuspecting world.