Decimal Integer to Base64

Encode a decimal integer directly as a Base64 string

Convert a decimal integer to its big-endian byte representation and encode it as Base64, or decode Base64 back to a decimal integer. Handles arbitrarily large numbers with BigInt, entirely in your browser. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

How is a number turned into Base64?

The integer is first written in its minimal big-endian byte form, most-significant byte first, with no leading zero bytes. Those raw bytes are then encoded with standard Base64. For example 65535 becomes the bytes FF FF, which encode to "//8=".

What this tool does

It bridges two representations: a plain decimal integer and a Base64 string. Base64 is defined over bytes, so a number is first serialised to its binary byte form and only then encoded. This is distinct from simply encoding the decimal digits of the number as text — the tool encodes the number’s binary value.

How it works

Encoding (decimal → Base64):

  1. The decimal value is parsed into a JavaScript BigInt.
  2. The integer is decomposed into its minimal big-endian byte sequence by repeatedly masking the lowest 8 bits and right-shifting, then reversing the byte array so the most-significant byte comes first. No leading zero bytes are included (except that zero itself becomes the single byte 0x00).
  3. Those raw bytes are encoded with standard Base64: every group of 3 bytes becomes 4 ASCII characters, with = padding if the byte count is not a multiple of 3.

Decoding (Base64 → decimal):

  1. The Base64 string is decoded back to bytes.
  2. The bytes are read big-endian into a BigInt: each byte shifts the accumulator left 8 positions and ORs in the next byte.

The tool shows the intermediate hex bytes at each step so you can follow the conversion.

Worked examples

DecimalHex bytesBase64
000AA==
255FF/w==
65535FF FF//8=
16777215FF FF FF////
1677721601 00 00 00AQAAAA==

Notice that 65535 encodes to //8= with two bytes, while 16777216 encodes to AQAAAA== with four bytes, because it requires a 01 most-significant byte.

When you need this

Compact numeric IDs in URLs. A large ID like 9007199254740991 is 16 decimal characters but encodes to 8 Base64 characters as bytes. Base64 URL IDs appear in short-link systems and API designs where byte-efficient identifiers matter.

Binary protocol encoding. Some network protocols pack integers into binary frames, then Base64-encode the frame for text transport. This tool lets you manually inspect or construct such values.

BigInt support. JavaScript’s Number.MAX_SAFE_INTEGER is 2^53 − 1. Because this tool uses BigInt internally, it handles integers far larger than that with no precision loss.

Important distinctions

  • This encodes the integer’s binary value, not its decimal digit characters. Encoding 255 gives \xFF in one byte → /w==, not the Base64 of the text “255”.
  • Standard Base64 uses + and / with = padding. If you need the URL-safe alphabet, replace + with - and / with _ after encoding.
  • Leading zero bytes in Base64 strings have no effect on the decoded integer value (unsigned big-endian), so multiple Base64 strings can produce the same integer. The encoder here always uses the minimal byte representation.