Fast RFC 4648-compliant Base64 encoding

Version on this page:0.4.1@rev:1
LTS Haskell 22.26:
Stackage Nightly 2024-06-22:1.0@rev:1
Latest on Hackage:1.0@rev:1

See all snapshots base64 appears in

BSD-3-Clause licensed by Emily Pillmore
Maintained by [email protected]
This version can be pinned in stack with:base64-0.4.1@sha256:aedc26f581f81a112af588eec8cf9c2e8db219a60fafc1cb77fd73672f1f7dcb,2832

Module documentation for 0.4.1

Depends on 3 packages(full list with versions):
Used by 1 package in lts-15.3(full list with versions):


Build Status Hackage

Padded and unpadded base64 and base64url encoding and decoding for Text and ByteString values.

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


What does this library provide? Here is the summary:

  • Good performance compared to existing Base64 libraries (see
  • Support for padded and unpadded Base64 and Base64url
  • Support for Text encodings and decodings
  • Optics for handling more complex structures with Base64 representations via the base64-lens package
  • Checks for both valid Base64 and correct Base64 and Base64url encodings

There are no dependencies aside from those bundled with GHC:

base64 dependencies


Haskell has two main libraries for Base64: memory, and base64-bytestring.

Of these, memory is geared towards integration with other memory primitives in the library, without much of an eye towards performance, while base64-bytestring is built to exclusively address ByteString encoding and decoding, and is very performant. Many great strides have been made in the realm of Base64 performance and vectorization just in the past 5 years, which this library attempts to capture. Additionally, we attempt to fix perceived shortcomings with both APIs in the support of unpadded Base64 and Base64-url support (which memory provides, but not base64-bytestring), as well as supporting Text values (neither libraries provide).


Revision history for base64

0.4.1 – 2020-02-04

  • Optimize loops for 32-bit and 64-bit architectures
  • Restructure project to be more amenable to swapping head/tail/loops
  • Fix module header alignment

0.4.0 – 2020-01-26

  • With this major version release, we remove the redundant encodeBase64Unpadded and decodeBase64Unpadded functions from Base64.hs. This is for two reasons:

    1. There is no reason for them to exist, since all std base64 is expected to be padded (in contrast to base64url)
    2. it was literally redundant with decodeBase64.
  • Use a specialized Bool type to give better visual cues regarding which functions add padding – 2020-01-15

  • Make sure benchmark code builds – 2020-01-08

  • Bug fix for isBase64 and isBase64Url - wrong alphabet was used
  • Added isValidBase64 and isValidBase64Url for alphabet conformity. The isBase64* functions now tell if it’s correct base64 now in the sense that it’s decodable and valid.
  • Dropped Cabal version to 2.0 for backcompat with Stack
  • Better documentation – 2020-01-07

  • After a discussion with lexilambda, we’re making ‘encodeBase64’ be ByteString -> Text by default, offering ByteString -> ByteString as a secondary format.
  • Add decodeBase64Lenient to the API for phadej
  • Fix unpadded decoding bug where garbage was appended to the end of garbage inputs. A cleaner way to do this is to simply encode as Base64 with padding and then strip padding chars until I come up with a workflow specific to unpadded inputs (I used to have this, so I’ll have to dig it up)
  • Added isBase64 and isBase64Url to the API
  • Performance is stable – 2020-01-05

  • After a discussion with phadej, we’re doing away with the flags, and splitting the optics out into their own separate library
  • Removed unnecessary inline pragmas – 2020-01-05

  • Do away with the typeclasses, and just provide prisms + synonyms
  • Continued performance improvements to decoding
  • Corrected benchmarks – 2020-01-03

  • First version. Released on an unsuspecting world.
  • Preliminary release