Convert hexadecimal to Base64

Convert hexadecimal to Base64 by decoding hex pairs into bytes, then encoding those bytes. Learn how to check input, padding and output compatibility.

To convert hexadecimal to Base64, decode the hexadecimal input into bytes, then encode those bytes as Base64. Each pair of hexadecimal digits represents one byte. This changes the representation of the data while preserving the underlying bytes; it does not reverse text, mirror characters or apply a visual style.

Convert the bytes, not the hexadecimal characters

For example, hexadecimal 48656c6c6f represents the bytes for Hello. Encoding those bytes as standard Base64 produces SGVsbG8=. Encoding the literal characters 48656c6c6f instead produces NDg2NTZjNmM2Zg==, which represents different data. Choose a workflow that explicitly decodes hexadecimal before applying Base64.

Hexadecimal input: 48656c6c6f
Base64 output:    SGVsbG8=

Prepare the hexadecimal input

  • 1. Check that the byte data uses hexadecimal digits: 0–9, A–F or a–f. Letter case does not change the value.
  • 2. Check that there is an even number of digits. Each byte requires two digits; do not silently add a leading or trailing zero.
  • 3. Identify any spaces, separators or 0x prefixes. Whether these are accepted depends on the converter, so follow its documented input format.
  • 4. Decode the hex pairs into bytes, then encode the resulting bytes using the Base64 variant required by the destination.

If the input represents a number rather than an existing byte sequence, first establish its byte order and required width. For example, 01 and 0001 have the same numeric value but describe different byte sequences and therefore produce different Base64 output. Preserve leading zero bytes when they are part of the data.

Choose the required Base64 format

Standard Base64 uses letters, digits, + and /, with = used for padding when needed. Base64url substitutes - and _ for + and /. Padding requirements can also differ between receiving formats. Use the destination’s specified variant and padding rules rather than changing characters or removing padding by guesswork.

Base64 encodes arbitrary bytes, so the input does not need to be readable text or valid UTF-8. If your source is ordinary text rather than hexadecimal, encode that text into bytes using an agreed character encoding before applying Base64. That is a separate starting point from decoding hex.

Check the conversion

Decode the Base64 result back into bytes and compare those bytes with the original hexadecimal input. Compare byte values rather than hex letter case or display spacing. A successful round trip confirms that the conversion preserved the data, but it does not establish that a receiving system accepts the chosen format.

Copying, readability and sensitive data

Base64 output uses ASCII characters and does not depend on fonts or visual styling. Its usefulness after copying depends on preserving the characters and satisfying the destination’s rules. Check for inserted line breaks, missing padding or altered punctuation. No destination documentation or scoped test was supplied, so acceptance by a particular application is unverified.

Base64 is intended for data exchange, not comfortable reading. No assistive-technology testing was supplied, so screen-reader behavior is unverified. When people need to understand the content, provide an ordinary-text explanation or, if the decoded bytes represent text and disclosure is appropriate, a readable version using the correct character encoding.

Base64 is not encryption and does not conceal sensitive information. No converter documentation was supplied to establish where processing occurs or whether input is transmitted or retained. Before submitting confidential data, verify those details or use an approved local conversion workflow.