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):
- The decimal value is parsed into a JavaScript BigInt.
- 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). - 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):
- The Base64 string is decoded back to bytes.
- 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
| Decimal | Hex bytes | Base64 |
|---|---|---|
| 0 | 00 | AA== |
| 255 | FF | /w== |
| 65535 | FF FF | //8= |
| 16777215 | FF FF FF | //// |
| 16777216 | 01 00 00 00 | AQAAAA== |
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
255gives\xFFin 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.