Skip to content
Base64 encode and decode without the use of Foundation in pure Swift.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Swift 5.1 github-actions codecov macOS tuxOS

This package provides a base64 encoder and decoder in pure Swift (without the use of Foundation). The implementation is RFC4648 complient.

Today the implementation is rather simple. No fancy precomputed lookup tables, no fancy SIMD instructions. Therefore, there is definitely room for improvement performance-wise. See also Literature for a faster algorithm.

Everything began with an issue on swift-nio.


  • support for base64 and base64url
  • faster than Foundation
  • decoding can ignore line breaks
  • encoding can insert line breaks

This package's encoding implementation is used in swift-nio's websocket implementation.


Super simple performance test to ensure speediness of this implementation. Encoding and decoding 1m times the base64 string:



MacBook Pro (15-inch, late 2016 - the first one with the butterfly keyboard). Quad Core 2.7 GHz Intel Core i7

Encoding Decoding
Foundation 2.21s 2.28s
swift-base64-kit 1.01s 1.06s
Speedup 2.18x 2.14x


Whatevar runs GitHub Actions 😉

Encoding Decoding
Foundation 33.64s 3.49s
swift-base64-kit 1.07s 1.27s
Speedup 31.18x 2.74x

I have no idea why Foundation base64 encoding is so slow on linux. 🤷‍♂️

Literature for a faster algorithm

I would really like to speed up this project further to be way faster than it is today. Some food for thought of how this could be tackled can be found here:


As of today (2019-12-10), the author is aware of only one alternative that offers merely encoding.

You can’t perform that action at this time.