Integer to Base64 Converter

Converts a list of integers (one per line) using this site's own integer/Base64 scheme: each value's absolute value is packed into the minimal big-endian byte array (at least 1 byte) and Base64-encoded, with a leading "-" prepended for negative numbers. This is not a standard encoding. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-27

Overview

Introduction

There's no widely agreed-upon way to represent a plain integer in Base64, so this tool defines a simple scheme of its own: pack the number's magnitude into the fewest bytes needed, Base64-encode those bytes, and prefix a "-" for negative values.

It's meant as a compact, copy-pasteable text form of a number rather than a replacement for any established binary format.

What Is Integer to Base64 Converter?

A converter that takes a list of integers, one per line, and outputs each one encoded with this site's own integer/Base64 scheme.

Each value's absolute value becomes a minimal big-endian byte array (at least 1 byte), which is then Base64-encoded; negative numbers get a leading "-" that sits outside the Base64 alphabet.

How Integer to Base64 Converter Works

For each integer, the tool computes the absolute value and repeatedly divides by 256 to build the minimal big-endian byte array representing that magnitude.

Those bytes are Base64-encoded using standard Base64 (the same alphabet used for MIME/JSON Base64).

If the original number was negative, a "-" character is placed in front of the encoded string.

When To Use Integer to Base64 Converter

Use it when you want a short, text-safe representation of a list of integers, such as for compact IDs or tokens in a URL-unsafe-character-free context (aside from the Base64 alphabet's own "+"/"/").

It's also a useful example for understanding how arbitrary data can be packed into bytes and then text-encoded.

Features

Advantages

  • Produces compact, printable strings shorter than a decimal or hex representation for the same value.
  • The sign prefix avoids any ambiguity with the Base64 alphabet itself.

Limitations

  • This is a site-specific scheme, not a standard; other tools and libraries won't recognize it without matching logic.
  • Limited to values within JavaScript's safe integer range (up to 2^53 - 1).

Examples

Small positive integer

Input

255

Output

/w==

Negative integer

Input

-255

Output

-/w==

Best Practices & Notes

Best Practices

  • Only use this encoding within contexts you control (like your own app), since it isn't a recognized standard elsewhere.

Developer Notes

Bytes are built with a `while (value > 0) { bytes.unshift(value % 256); value = Math.floor(value / 256); }` loop rather than bitwise operators, so the arithmetic stays correct beyond the 32-bit range bitwise operators are limited to, up to `Number.MAX_SAFE_INTEGER`.

Integer to Base64 Converter Use Cases

  • Generating compact, printable tokens from small integer IDs
  • Demonstrating how integers can be packed into bytes and text-encoded
  • Producing a shorter alternative to decimal or hex for storage or display

Common Mistakes

  • Assuming this matches some other system's "integer to Base64" behavior; it's this site's own scheme.
  • Trying to encode integers beyond the safe integer range, which can lose precision before encoding even happens.

Tips

  • Use the companion Base64 to Integer Converter to decode values produced by this tool and confirm round-tripping.

References

Frequently Asked Questions