Hex to Base64 Converter

Hex to Base64 Converter. Paste your bytes into Hex Input and the Hex to Base64 Converter instantly encodes them into Base64 Output. Use the decimal to hex converter to turn a plain decimal value into hex digits without doing the division by 16 yourself.

Need to move binary data through a channel that only accepts text? This hex to base64 converter is a free online tool that turns a hexadecimal string into a compact Base64 string, so you can base64 encode a checksum, key or payload instantly. Paste your input, and the online tool returns an encoded value you can drop straight into a header, a JSON field or a config file, then reverse it whenever you need to.

Using the Hex to Base64 Converter Step by Step

The hex to base64 converter takes a hex string as input and returns a base64 string as output. Each pair of digits describes a single byte, so it first rebuilds the original binary data and then writes that data out again with the 64-character Base64 alphabet. Nothing about the underlying data changes; only how it is written does.

  1. Paste or type your hex values into the input box. Spaces and a leading 0x are ignored.
  2. Make sure the input has an even length, because every byte needs two digits.
  3. Click the Convert button to run the conversion.
  4. Copy the resulting string, including any trailing = signs.

If you only need to convert hex to base64 once, that is the whole job. The rest of this guide explains what happens between your input and the output, so you can trust the result and spot mistakes quickly.

What the converter accepts

Valid input uses only the symbols 0-9 and A-F, in either case. Anything else, such as the letter G or a stray comma, is not a hexadecimal character and produces an error rather than a silent guess. An odd number of digits is rejected as well, since half a byte cannot be encoded.

Hexadecimal vs Base64 Encoding Explained

Both are ways to write the same data as printable text. They simply use different alphabets, and each one trades readability against size. The quickest way to check the binary form of an octal number is the octal to binary converter, which updates live without a separate Convert step.

Hexadecimal and the base-16 number system

Hexadecimal is a base-16 number system that uses sixteen symbols. Each hex digit stands for four bits, so a pair covers a full byte. Programmers lean on it for memory addresses, hex dumps, debugging sessions and colors in web development, because it is easy to read next to the raw bits.

Base64 as binary-to-text encoding

Base64 encoding is a binary-to-text encoding scheme. It draws on the base64 characters A-Z, a-z, 0-9, plus + and /: 26 uppercase letters, 26 lowercase letters and 10 digits make 62, and the two symbols bring the total to 64. Every output character carries six bits, which is why Base64 is shorter than hex for the same data.

Base64 as binary-to-text encoding
PropertyHexadecimalBase64
Bits per character46
Characters for 3 bytes64
Size overhead vs the original data100%about 33%
Alphabet16 symbols64 symbols
Typical useDebugging, hashes, ASCII dumpsEmail, JSON, XML, tokens

Because Base64 needs only four characters where hex needs six, it is the better choice whenever size matters. Hex wins when a human has to read the bytes one by one.

How Hex to Base64 Conversion Works

The hex to base64 conversion is pure bit shuffling, and you can do it by hand. Every hex to base64 conversion follows the same four stages: expand each digit into bits, regroup the bits, look each group up in the encoding table, and finish with padding if the length requires it. The hex to base32 converter is a straightforward way to produce standard Base32 text from an existing hex byte string.

  1. Expand to binary. Each hex digit becomes four bits, so 4 is 0100 and F is 1111.
  2. Regroup into 6-bit chunks. The long stream of bits is cut every six positions instead of every four.
  3. Map each chunk. A value from 0 to 63 selects one character from the encoding scheme alphabet, so 0 is A and 63 is /.
  4. Pad the tail. The result must be a multiple of four characters long, so = fills any gap.

The formula behind the output length

Three bytes (24 bit in total) become four characters. For an input with \(h\) digits, the byte count is \(n = h / 2\), and the length of the encoded output follows directly from it:

$$L_{\text{Base64}} = 4 \times \left\lceil \frac{n}{3} \right\rceil$$

Here \(L_{\text{Base64}}\) is the length of the base64 string and \(\lceil\ \rceil\) rounds up to the next whole number. A 12-digit input describes 6 bytes, so the output is \(4 \times \lceil 6/3 \rceil = 8\) characters long.

Worked example: converting 446F636B2037

Take the input 446F636B2037. It has 12 digits, so it holds six bytes, which happen to spell the ASCII text Dock 7. Writing each one as eight bits and cutting the stream into 6-bit groups gives this table:

Worked example: converting 446F636B2037
Hex bytesBit pattern6-bit groupsIndexBase64
44 6F 6301000100 01101111 01100011010001 000110 111101 10001117, 6, 61, 35R G 9 j
6B 20 3701101011 00100000 00110111011010 110010 000000 11011126, 50, 0, 55a y A 3

Reading the last column left to right, 446F636B2037 becomes RG9jayA3. The 6 input bytes needed exactly two full groups of three, so no extra characters were needed.

Padding Characters and Base64URL Output for Hex Values

Padding exists because the encoder works on blocks of three bytes. When the data does not divide evenly, the encoder adds padding characters so the length stays a multiple of four.

Padding Characters and Base64URL Output for Hex Values
Hex inputBytesRemainderBase64 output
4F11 byte leftTw==
4F6B22 bytes leftT2s=
4F6B213noneT2sh

URL-safe encoding for web addresses

The plus and slash symbols clash with web addresses, so a url-safe variant called base64url swaps them for a hyphen and an underscore and usually omits the = signs. Pick that form when the value goes into a URL, a filename or a token, and keep the standard form for everything else.

Turning a Hex Checksum into a Base64 String for an S3 Upload

Marcus Ibáñez, a backend developer, is about to upload invoice-2291.pdf to Amazon S3 and wants the service to verify the file on arrival. S3 accepts a SHA-256 checksum in the x-amz-checksum-sha256 header, but it expects the digest as a Base64 value. His build script, like most command-line hashing tools, prints the digest as hex.

The script prints this 64-digit value:

95343ea6c7a7e588555c17981e668b409a6a22abb8e671ff21ceb784603e49b1

He pastes it into the converter and clicks Convert. The 64 digits describe 32 bytes, so the length formula predicts \(4 \times \lceil 32/3 \rceil = 44\) characters. The page returns exactly that:

lTQ+psen5YhVXBeYHmaLQJpqIqu45nH/Ic63hGA+SbE=

Two details tell him the result is sound. The string is 44 characters long, and it ends in a single =, which fits 32 bytes leaving a remainder of two bytes in the final block. It also contains a + and a /, so it is the standard alphabet rather than the URL-safe one, and S3 headers expect the standard form.

The next step is a concrete one. Marcus adds x-amz-checksum-sha256: lTQ+psen5YhVXBeYHmaLQJpqIqu45nH/Ic63hGA+SbE= to the request. Had he pasted only 63 digits by mistake, the converter would have refused the odd-length input, so a bad copy could not slip through quietly. S3 now recomputes the digest on its side, and if even one bit of the PDF changed in transit, the upload fails with a checksum mismatch instead of storing a damaged invoice.

Why Base64 Encoding Suits Text-Based Systems

Many text-based systems and older network protocols were built for printable ASCII characters, not arbitrary raw bytes. Pushing binary through them risks corruption, so the data gets wrapped in text first. Other systems, such as log viewers, simply display whatever they receive, which makes a printable form the safest option.

Compatibility and data integrity

Base64 only uses safe characters, which protects data integrity across mail systems and proxies that might alter control codes. That is the point of text-based protocols such as HTTP and the MIME format used by email: they stay readable while carrying image attachments and other files.

Data transfer and size reduction

Switching from hex to Base64 gives a size reduction of about a quarter for the same payload. For a stream of messages, that saves bandwidth and speeds up data transfer. Shorter strings also improve usability, since long hex strings invite human error when you are copying them by hand.

Where developers use the result

  • Data transmission in headers and API calls over HTTP and other network protocols.
  • Attachments and uploaded binary files that travel inside text messages.
  • Storage of binary values inside JSON and XML documents.
  • Cryptographic keys and certificates, which are exchanged as encoded text.
  • Configuration files that cannot hold raw binary.

Hexadecimal to Base64 in Python, JavaScript and Go

Every mainstream language handles this in two calls, which is why developers rarely write the algorithm themselves. Use a built-in or standard libraries function instead of hand-rolled loops. The same steps apply everywhere: parse the hex into bytes, then encode the bytes.

Python

import base64
hex_string = "446F636B2037"
print(base64.b64encode(bytes.fromhex(hex_string)).decode())  # RG9jayA3

JavaScript

const hex = "446F636B2037";
const b64 = Buffer.from(hex, "hex").toString("base64");
console.log(b64); // RG9jayA3

Java

Since Java 17 the HexFormat class parses the digits, and Base64.getEncoder() does the rest, so no third-party code is needed.

In Go, the encoding/hex and encoding/base64 packages play the same roles: parse the string into bytes, then call EncodeToString on the resulting slice. These built-in functions and libraries are tested far more than any custom code and handle programming edge cases for you.

Troubleshooting Hexadecimal Input and Output Errors

Most failed conversions come from the input, not the converter. If the output looks wrong, work through these checks before you blame the tool.

  • Odd length. A missing or extra digit shifts every later byte, so the whole result changes. Count the digits first.
  • Hidden characters. Text copied from a PDF or terminal sometimes carries invisible separators that break the conversion.
  • Wrong source. Hex that came from a text document describes the characters of that text, not the binary files you meant to encode.
  • Byte order. Encoders read hex left to right, so reversing a little-endian value gives a different binary result.

Run a short known value such as 4F through the page in your browser, compare it to the expected Tw==, and you will know within seconds whether the tool, the clipboard or the source file is at fault. Because the converter is deterministic, the same input always yields the same output, so any difference points at the source value rather than the conversion method.

Best Practices for Safe Base64 Encoding of Hex Values

A few habits prevent the most common faults when you encode hex data. Treat these best practices as a quick checklist for any computing task that involves encoded binary.

  • Validate input. Reject strings with an odd length or non-hex symbols before the encoding step runs.
  • Handle padding correctly. Keep the = signs unless the receiving system expects the unpadded form.
  • Test in a browser. Paste a known value into the page and compare before you automate anything.
  • Check the character set. Convert text using one agreed character set, ideally UTF-8, to avoid character set compatibility problems.
  • Operate on bytes. Always convert to bytes first and use hex and Base64 only for display.
  • Mind line length. MIME output (RFC 2045) wraps at 76 characters with a newline; plain output has no line breaks. For URLs, RFC 4648 defines the safe alphabet, and a standard string must be percent-encoded otherwise.

Decoding Base64 to Hex: Is the Process Reversible?

Yes. The process is fully reversible, because no information is lost in either direction. To reverse it, use a base64 to hex tool: it drops the = signs, maps each character to six bits, regroups them into bytes and writes each byte as two hex digits. The same decoding step lets you decode any string you receive and verify it against the original hex. A quick round trip is the simplest sanity check: encode a value, reverse it, and confirm that the digits you get back match the ones you started with.

Security-minded readers should note that converting hex to Base64 does not protect the data, because Base64 is not encryption. Anyone can reverse it, so never treat an encoded secret as protected, and keep your privacy expectations tied to a real cipher and a secure SSL connection, not to the encoding.

For learning, the first challenge of the cryptopals set asks for exactly what the converter does, with pretty-printing as the only reason to use hex or Base64 at all. It is a good way to see how the whole algorithm fits together and to meet the standard and specification language used by browsers and servers alike.