Base58 Encoder & Decoder (Bitcoin & IPFS)

Encode and decode text and byte arrays to Base58 using standard Bitcoin and Ripple/Flickr character sets.

4.9 / 5· 148 verified ratings
•
100% Client-Side Privacy
•
Verified 2026 Engine
Instant Computation • 100% Client-Side Privacy • Zero Server Upload
Loading tool engine...
Frequently Used With:JSON Formatter & Validator →JSON Diff & Comparison Tool →XML to JSON Converter →YAML to JSON Converter →
Institutional-Grade Accuracy & Client-Side Privacy Guarantee

Unlike conventional calculator sites that send your financial numbers, payload data, or code snippets across remote web servers, Affi-Chain processes all mathematical derivations, algorithms, and data parsing 100% locally within your browser sandbox. No tracking cookies, no server-side retention, and zero transmission lag.

What is Base58 Binary-to-Text Encoding?

Base58 is a specialized binary-to-text encoding algorithm designed by Satoshi Nakamoto in 2008 for the original Bitcoin reference client. In distributed cryptographic ledgers, decentralized networks, and peer-to-peer protocols, binary cryptographic artifacts—such as 256-bit elliptic curve public keys, digital signatures, hash digests, and addresses—must frequently be copied, transcribed, printed, and shared by human users.

Standard binary-to-text encodings like Base64 or Hexadecimal present substantial usability and reliability challenges when handled by humans. Base64 relies on characters that look visually identical in many monospace and sans-serif typefaces, and it includes non-alphanumeric punctuation marks (+ and /) that trigger line-breaking, double-click selection failures, and URL percent-encoding overhead.

To solve this, Base58 eliminates punctuation and visually ambiguous glyphs, creating a compact, human-friendly, double-click selectable representation. Today, Base58 is the foundational encoding for Bitcoin addresses (P2PKH, P2SH), Solana public keys and transaction signatures, IPFS Content Identifiers (CIDs), and Monero wallet addresses.

The Affi-Chain Base58 Encoder & Decoder provides instant, 100% in-browser bidirectional conversion between raw text strings, hex byte arrays, and Base58 strings using native BigInt arithmetic with complete privacy.


The Base58 Alphabet & Ambiguity Elimination Matrix

The standard Bitcoin Base58 alphabet consists of exactly 58 alphanumeric characters:

$$\text{Alphabet: } \texttt{123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz}$$

To arrive at 58 characters from the standard 64-character alphanumeric set, Satoshi Nakamoto deliberately removed 6 characters:

Excluded CharacterCharacter TypeReason for Exclusion
0Number ZeroIndistinguishable from uppercase letter O in standard fonts
OCapital Letter OIndistinguishable from number zero 0
ICapital Letter IIndistinguishable from lowercase letter l or number 1
lLowercase Letter LIndistinguishable from uppercase letter I or number 1
+Plus SignCauses word-wrapping breaks; triggers URL percent-encoding (%2B)
/Forward SlashConflicts with file system paths and URL delimiters (%2F)

Mathematical Base Conversion Mechanics & Leading Zeros

Unlike Base64, which operates on discrete 6-bit chunks ($2^6 = 64$), Base58 is not a power of two ($58 \ne 2^n$). Therefore, Base58 encoding requires whole-number arbitrary-precision arithmetic:

1. Base Conversion via Arbitrary Precision Modulo

The raw byte array is treated as a single large unsigned integer in base-256 ($N$). The algorithm repeatedly divides $N$ by 58, capturing remainders: $$\text{Remainder } r = N \bmod 58$$ $$N = \lfloor N / 58 \rfloor$$ Each remainder $r$ indexes directly into the 58-character alphabet string. The process terminates when $N = 0$, and the resulting characters are reversed.

2. The Leading Zero Preservation Rule

Because numeric zero ($0$) divided by 58 yields zero, standard base conversion mathematically discards leading zero bytes (0x00). In cryptography, leading zero bytes are semantically critical:

  • In Bitcoin, 0x00 is the network version byte designating mainnet addresses.
  • To preserve these bytes, Base58 specifies that every leading 0x00 byte in the binary input must be prepended as the character 1 in the encoded string. For example, a Bitcoin address with two leading zero bytes begins with 11.

3. Base58Check: The Error-Detecting Variant

To prevent catastrophic financial loss from typographical errors, Bitcoin wraps Base58 in Base58Check: $$\text{Checksum} = \text{SHA256}(\text{SHA256}(\text{Version} + \text{Payload}))[0..3]$$ The 4-byte checksum is appended to the payload before Base58 encoding. When a wallet decodes the address, it recalculates the checksum; if a single character was mistyped, verification fails, preventing accidental transfers to non-existent addresses.


Practical Code Implementation: Lossless Base58 Engine

Below is a complete JavaScript implementation utilizing native BigInt for arbitrary-precision arithmetic and exact leading-zero preservation:

/**
 * Production Base58 Encoder and Decoder (Bitcoin Alphabet).
 */
class Base58 {
  static ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
  static BASE = BigInt(58);

  /**
   * Encodes a Uint8Array buffer into a Base58 string.
   */
  static encode(bytes) {
    if (!bytes || bytes.length === 0) return "";

    // 1. Count leading zero bytes (0x00)
    let leadingZeros = 0;
    while (leadingZeros < bytes.length && bytes[leadingZeros] === 0) {
      leadingZeros++;
    }

    // 2. Convert remaining bytes to BigInt
    let intVal = BigInt(0);
    for (let i = leadingZeros; i < bytes.length; i++) {
      intVal = (intVal << BigInt(8)) + BigInt(bytes[i]);
    }

    // 3. Repeated division by 58
    let result = "";
    while (intVal > BigInt(0)) {
      const mod = intVal % Base58.BASE;
      intVal = intVal / Base58.BASE;
      result = Base58.ALPHABET[Number(mod)] + result;
    }

    // 4. Prepend '1' for each leading zero byte
    return "1".repeat(leadingZeros) + result;
  }

  /**
   * Decodes a Base58 string back to a Uint8Array.
   */
  static decode(str) {
    if (!str || str.length === 0) return new Uint8Array(0);

    // 1. Count leading '1' characters
    let leadingOnes = 0;
    while (leadingOnes < str.length && str[leadingOnes] === "1") {
      leadingOnes++;
    }

    // 2. Convert string to BigInt
    let intVal = BigInt(0);
    for (let i = leadingOnes; i < str.length; i++) {
      const charIndex = Base58.ALPHABET.indexOf(str[i]);
      if (charIndex === -1) {
        throw new Error(`Invalid Base58 character detected: "${str[i]}"`);
      }
      intVal = (intVal * Base58.BASE) + BigInt(charIndex);
    }

    // 3. Convert BigInt back to byte array
    const hex = intVal.toString(16);
    const paddedHex = hex.length % 2 === 0 ? hex : "0" + hex;
    const byteLength = paddedHex.length / 2;
    const bytes = new Uint8Array(leadingOnes + byteLength);

    for (let i = 0; i < byteLength; i++) {
      bytes[leadingOnes + i] = parseInt(paddedHex.slice(i * 2, i * 2 + 2), 16);
    }

    return bytes;
  }
}

// Verification Example (Solana public key bytes):
const textEncoder = new TextEncoder();
const rawBytes = textEncoder.encode("Hello Affi-Chain");
const encoded = Base58.encode(rawBytes);
console.log("Encoded Base58:", encoded);

const restoredBytes = Base58.decode(encoded);
const restoredText = new TextDecoder().decode(restoredBytes);
console.assert(restoredText === "Hello Affi-Chain", "Lossless round-trip passed");

Comparison Matrix: Binary Encodings Across Cryptography & Web

EncodingBase ($N$)Character SetHuman ReadabilityLeading Zero PreservationPrimary Use Case
Base5858Alphanumeric (minus 0, O, I, l)High (No ambiguous chars)Yes (via prepended '1')Bitcoin, Solana, IPFS, Monero
Base6464A-Z, a-z, 0-9, +, /, =Moderate (includes symbols)Yes (via bit alignment)MIME emails, JWTs, Data URIs
Hex (Base16)160-9, a-fLow (long string length)YesEthereum addresses, hash digests
Bech3232Lowercase alphanumeric onlyVery High (includes BCH error code)NativeSegWit / Taproot Bitcoin addresses

Critical Edge Cases & Common Traps

1. Incompatible Alphabet Variants

While Satoshi Nakamoto's alphabet is standard across Bitcoin, Solana, and IPFS, alternative systems use different alphabets:

  • Ripple Alphabet: Starts with lowercase r (rnsk7B...) to ensure all Ripple addresses begin with the letter r.
  • Flickr Alphabet: Uses a different sort order designed for short URL identifiers. Always verify that the target protocol uses the standard Bitcoin alphabet before validating addresses.

2. Forgetting Leading Zero Bytes in Custom Handlers

A classic bug in naive BigInt implementations is converting bytes to a number and back without tracking leading zeros. A 32-byte hash starting with 0x00 0x00 0x1A will decode into only 30 bytes instead of 32 bytes, causing cryptographic signature verification to fail. Always prepend the leading '1' count.

Frequently Asked Questions

Why does Base58 exclude 0, O, I, and l?
Base58 intentionally eliminates visually ambiguous characters (number 0, uppercase O, uppercase I, lowercase l) and non-alphanumeric punctuation to prevent transcription errors.

Explore Related Utilities