Base64 to Hex Converter

Base64 to hex converter: paste Base64 and get the bytes as hex, for hashes, keys and binary data. Choose the separator and letter case. Standard and URL-safe input both work, and Swap converts hex back to Base64. Nothing leaves your browser.

Base64 to hex
Standard or URL-safe, padded or not
4 bytes · 11 characters out
Your input stays in this browser

Base64 to hex: decode the bytes, then write them in hexadecimal

Base64 and hexadecimal are two ways of writing the same bytes. Base64 packs six bits into each character and hex packs four. Converting from one to the other therefore goes through the bytes: decode the Base64 into bytes, then write each byte as two hex digits. The converter performs both steps, shows how many bytes it found, and lets you pick the separator and the letter case of the result.

Hex is the form that people compare. A SHA-256 digest in a file listing, a certificate fingerprint in a browser dialog and a key in a configuration file are almost always hex, and the same value often arrives in Base64 from an API, a lock file or an HTTP header. Turning one into the other is the daily need this page covers.

Why the digits cannot be converted one by one

With hex and binary, each digit maps to four bits and a conversion works digit by digit. Base64 does not line up with hex that way, because 6 and 4 share a common multiple only at 12 bits. Two Base64 characters would be three hex digits, but bytes are 8 bits, and the groups in Base64 are aligned to three bytes (24 bits, four characters). The first characters of a Base64 string and the first digits of its hex form therefore do not correspond.

Four bytes in hex and in Base64The bytes DE AD BE EF are eight hex digits, one pair per byte, and the Base64 text 3q2+7w==, where three bytes make four characters and the fourth byte starts a new group.bytes11011110101011011011111011101111hexDEADBEEFBase643q2+7w==bytes 1–3 → characters 1–4 · byte 4 → characters 5–6 and padding
4 bytes are 8 hex digits or 8 Base64 characters. Hex aligns with bytes; Base64 aligns with groups of three, so the two strings cannot be compared by position.

For this reason a mismatch at one position says nothing about the position in the other form, and a change of a single byte can alter two Base64 characters. When you compare two values, convert both to the same form first. The reliable method is the one the tool uses: decode fully, then encode the bytes.

A worked example: 3q2+7w== is DEADBEEF

Take the string 3q2+7w==. Its characters are looked up in the alphabet: 3 is 55, q is 42, 2 is 54, + is 62, 7 is 59 and w is 48. The two = signs are padding and carry nothing. Written as six-bit groups, the first four characters are 110111 101010 110110 111110, which join into the 24 bits for the first three bytes. The last two characters, 7w, give 12 bits, of which only the first eight are data, which is the fourth byte.

3q2+7w== decoded into bytes and hex
ByteBinaryHexDecimal
111011110DE222
210101101AD173
310111110BE190
411101111EF239

The bytes are DE AD BE EF, which is the value DEADBEEF. The 32 bits regroup as 110111 101010 110110 111110 111011 11: the last group is two bits and the encoder pads it with four zero bits to make the sixth character, w. Those four spare bits are why the string ends in two = signs, and why a strict decoder checks that they are zero.

Hashes and keys: lengths in Base64 and hex

A digest has a fixed length in bytes, and so a fixed length in each text form. The lengths are a quick test of what a string is, and of whether it has been cut. The table is calculated from the byte counts.

Digest lengths in bytes, Base64 and hex
AlgorithmBytesBase64 characters (padded)Hex digits
MD5162432
SHA-1202840
SHA-256324464
SHA-384486496
SHA-5126488128

The Base64 forms of MD5, SHA-1 and SHA-256 all end in padding (24, 28 and 44 characters), because 16, 20 and 32 bytes are not multiples of three, while SHA-384 is 48 bytes, a multiple of three, and so has none: its 64 characters end without an equals sign. That detail is a handy check: if a SHA-384 digest in Base64 ends in =, something is wrong. SHA-512 at 64 bytes leaves one byte in the last group and ends in two = signs.

A worked example with a real digest: SHA-256 of the letter a

The SHA-256 hash of the single character a is a 32-byte value. Hash tools print it as the 64 hex digits ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb, and APIs and lock files write it as the 44-character Base64 string ypeBEsobvcr6wjGzmiPcTaeG7/gUfE5yuYB3ha/uSLs=. Both are the same 32 bytes, and the converter turns one into the other in either direction. The Base64 version ends in a single =, because 32 bytes are ten full groups of three and a short group of two.

Two checks confirm the conversion. The byte count must be 32, shown under the output. And the first byte of the hex, CA, must agree with the first six bits of the Base64: y is 50, which is 110010, and the first byte is 11001010, so the first six bits are 110010 and the next two bits, 10, begin the second character p, whose value 41 is 101001 and starts with those bits. In the URL-safe form of the same digest the / characters become _, and the padding is dropped: ypeBEsobvcr6wjGzmiPcTaeG7_gUfE5yuYB3ha_uSLs. All three strings convert to the same hex.

Certificate and SSH key fingerprints

Fingerprints are the place where the two forms meet most. A TLS certificate's SHA-256 fingerprint is shown by browsers and tools as 32 hex pairs separated by colons, for example 3A:7F:… in upper case. The same hash can appear Base64-encoded in a pinning configuration, in a Content-Security-Policy hash source or in a certificate transparency log entry. OpenSSH prints key fingerprints as SHA256: followed by Base64 without padding, and older versions printed the MD5 form as hex pairs with colons.

To compare a fingerprint shown in one form with a value in the other, convert the Base64 with the colon separator and upper case, and compare pair by pair. A match of all 32 pairs is a match of the key; a mismatch anywhere is a different key. An OpenSSH Base64 fingerprint of 43 characters corresponds to 64 hex digits; the missing = is expected, so give the tool the string as it is shown.

UUIDs and compact identifiers

A UUID is 16 bytes and is usually written as 32 hex digits in the groups 8-4-4-4-12. Some systems store the same 16 bytes as a 22-character Base64URL string without padding, which is shorter and safe in a URL. Converting means decoding the 22 characters to 16 bytes and writing them as hex, then inserting the hyphens after digits 8, 12, 16 and 20. A 22-character result with 16 bytes behind it is the usual sign that an identifier is a UUID in Base64URL form.

The reverse works the same way. Strip the hyphens, convert the 32 hex digits to Base64URL and drop the padding. The identifier is unchanged; only its spelling is. Microsoft's GUID text form is the same 16 bytes, though the first three groups are stored in little-endian order inside the binary layout used by some Windows APIs, so a byte-for-byte conversion of a raw GUID structure differs from the text form in the order of those groups.

Byte order and reading the hex as a number

The hex that comes out lists the bytes in the order they were stored, first byte first. That is not always the order in which a number reads. A 4-byte integer in Base64 such as AAAA/w== is the bytes 00 00 00 FF, and as a big-endian number it is 255; the same value in little-endian form would be the bytes FF 00 00 00, which in Base64 is /wAAAA==. If the bytes are a number, the specification of the format says which order applies, and a hex view of the bytes lets you reverse them correctly.

Keys, nonces and signatures in both forms

Cryptographic material is made of bytes of a fixed size, and the size identifies it. An AES-128 key is 16 bytes, an AES-256 key 32 bytes, and the nonce for AES-GCM is normally 12 bytes. Configuration files and environment variables carry them in Base64, while documentation and test vectors print them in hex, so a conversion is a routine step when checking that a key was loaded correctly.

Common binary values: size in bytes and length in each form
ValueBytesBase64 (padded)Base64URL (unpadded)Hex digits
AES-GCM nonce12161624
AES-128 key16242232
AES-192 key24323248
AES-256 key, HMAC-SHA-256 output32444364
SHA-512 digest648886128

The 43 characters of the unpadded form explain a detail of JSON Web Tokens: the signature of an HS256 token is an HMAC-SHA-256 value of 32 bytes, so it always appears as a 43-character URL-safe string. If a key is shorter than expected after conversion, the Base64 was truncated, and if it is longer, there is often a trailing line feed encoded into it.

Checking a download against a published hash

Software releases publish hashes in one form, and the tools you have print another. Most operating systems print hex: sha256sum file on Linux and Get-FileHash in PowerShell. Others publish Base64, as the Subresource Integrity and package manager formats do. To compare, convert one side. If the release lists a Base64 SHA-256, you can produce the same form directly with openssl dgst -sha256 -binary file | openssl base64, or convert the Base64 to hex here and compare it with the output of sha256sum.

The comparison has to be exact. A match of the first and last few characters is not a verification, because an attacker can search for values that agree in those places, and a hash compared as text should be brought to a common case. Check the byte count too, which is 32 for SHA-256, since a truncated hash compares equal to a prefix of the real one.

Binary payloads from devices and gateways

Embedded devices send compact binary messages, and the networks that relay them wrap the bytes in Base64 inside JSON. LoRaWAN network servers, for example, deliver the application payload as a Base64 string in the uplink message. To read it, convert to hex and apply the device's payload format. The string AWcBEA== is the four bytes 01 67 01 10; in the Cayenne LPP format used by many sensor examples, that reads as channel 1, type 67 (temperature), value 0110 hex, which is 272 tenths of a degree, 27.2 degrees Celsius.

The same flow applies to MQTT and other message systems that put Base64 in a text field. Convert the string, read the hex against the payload specification, and take care with byte order and signed values, which the hex to decimal page covers.

Converting in a database or a spreadsheet

In PostgreSQL, encode(decode(col, 'base64'), 'hex') turns a Base64 column into hex, and HEX(FROM_BASE64(col)) does the same in MySQL. Spreadsheets have no Base64 function in the formula language, but Power Query in Excel can decode with Binary.FromText and show the bytes, and a short script is the usual route for a whole column. For a handful of values, pasting them here is quicker than any of these.

Where Base64 digests and keys turn up

Several everyday formats write digests in Base64 while the tools you compare them with print hex. Subresource Integrity attributes on script and link elements carry a Base64 hash, as in integrity="sha384-…". npm's lock files record package integrity as sha512- followed by Base64. Docker, Git and package managers show the same digests as hex, so verifying a download means converting one of them.

Authentication material follows the same split. HTTP digest headers and the thumbprints inside JWTs (the x5t field is a Base64URL SHA-1 of a certificate) are Base64, while the fingerprint a browser or operating system displays for the same certificate is hex, often upper case with colons between bytes. Converting with colons and upper case gives the form that certificate dialogs use, and converting the hex back gives the Base64 that a configuration expects.

URL-safe Base64 as input

Input from a URL, a JWT or a file name uses - and _ in place of + and /, and usually omits the padding. The converter accepts both alphabets and reports which it read, so you can paste a JWT part or a token from a query string unchanged. A string with both kinds of characters is reported as mixed, because standard decoders would reject it.

The hex that comes out is the same whichever alphabet the input used, as the alphabet affects only the text form. That also means that a Base64URL fingerprint and the standard Base64 of the same bytes convert to the same hex, which gives a simple way to check that two differently formatted values are the same data.

Separators, case and the form of the hex

The default output is upper-case pairs separated by spaces, which reads well and matches most debugger output. Choose no separator for the compact form used in checksums and configuration files, a colon for fingerprints, a comma when pasting into a list, or a hyphen for the form Windows PowerShell prints. Case is cosmetic for the value but matters for text comparison: compare hex strings only after bringing both to one case.

3q2+7w== in the separator options
SeparatorOutput
SpaceDE AD BE EF
NoneDEADBEEF
ColonDE:AD:BE:EF
CommaDE,AD,BE,EF
HyphenDE-AD-BE-EF

Verifying a conversion with a second method

When the value matters, convert it twice by different routes. On the command line, echo STRING | base64 -d | xxd -p gives the hex, and a one-line script in Python or Node gives it again; if the converter agrees with both, the conversion is right. For a digest, the byte count is a built-in check: the converter reports 16, 20, 32 or 64 bytes for the common algorithms, and any other count means the input is not that digest.

A last check, which costs nothing, is to run the output through the Swap button and compare the Base64 that comes back with the string you started with. Ignoring padding and alphabet, they must be equal. If the round trip fails, the input had spare bits set in its last character, or characters that the decoder reported as invalid. In both cases the report says where.

Hex to Base64: the same conversion backwards

The Swap button turns the result into the input of the opposite conversion, and the hex to Base64 page has the same tool with its own length table and URL-safe examples. Hex goes in with any of the usual notations (plain, spaced, 0x or \x prefixes, colons), the pairs become bytes, and the bytes are encoded in standard or URL-safe Base64 with padding. The hex needs an even number of digits; an odd count is reported with the position of the digit that has no partner. If you only need the encoding of a text string, Base64 encode starts from text instead of hex.

Round trips make a good test. Converting the hex output back must reproduce the original Base64 string exactly, apart from the padding if the input had none and from the alphabet if the input was URL-safe. If the round trip differs in any other way, the Base64 input had non-zero bits in its last character, which the encoder always writes as zeros.

Errors and length checks

An invalid character in the Base64 is reported with its position. The usual culprits are copied quotes, a space where a + sign should be, or a line of JSON escaping. After conversion, check the byte count against the algorithm: 32 bytes for a SHA-256 digest or a 256-bit key, 16 for an MD5 digest or an AES-128 key. A result of 33 bytes when you expected 32 often means a trailing line feed was encoded into the original string, which adds 0A at the end.

If the bytes are meant to be text, the hex is only a view, and the Base64 decoder shows the text itself. When the hex is a file, the first bytes tell you which: 89 50 4E 47 is a PNG, 25 50 44 46 is a PDF. The hexadecimal page explains the notation and its conventions.

Base64 to hex in Python, JavaScript and the shell

Python and JavaScript
import base64
base64.b64decode("3q2+7w==").hex()                      # 'deadbeef'
base64.b64decode("3q2+7w==").hex(":")                   # 'de:ad:be:ef'

Buffer.from("3q2+7w==", "base64").toString("hex")       // 'deadbeef'
Array.from(atob("3q2+7w=="), c => c.charCodeAt(0).toString(16).padStart(2, "0")).join("")   // browser
Command line and PowerShell
echo 3q2+7w== | base64 -d | xxd -p                         # deadbeef
echo 3q2+7w== | base64 -d | od -An -tx1                    # de ad be ef

[BitConverter]::ToString([Convert]::FromBase64String("3q2+7w=="))     # DE-AD-BE-EF
[Convert]::ToHexString([Convert]::FromBase64String("3q2+7w=="))       # DEADBEEF (PowerShell 7, .NET 5 and later)

Beware of the same trap on the command line as in the encoder: echo adds a line feed, which Base64 would encode if you convert in the other direction. In decoding it is harmless, because a decoder ignores whitespace.

Common mistakes

Large values and files

The converter has no fixed size limit, but hex output is twice the size of the bytes and a browser text field becomes slow with millions of characters. For a file of more than a few hundred kilobytes, use the command line: base64 -d file.b64 | xxd -p streams the bytes and does not hold the whole result in memory. Hex is not the right view of a large binary anyway; the useful information is usually the first bytes (the file signature), the length and a digest, all of which the tool shows for what you paste.

Which converter for which job

Related conversions and where to do them
You haveYou wantUse
Base64 textThe bytes as hexThis converter
HexBase64Swap, in this converter
Base64The text it holdsBase64 decode
TextBase64Base64 encode
Hex pairsThe charactersHex decoder
A string of unknown typeA guess at the encodingAuto decoder
A number in hexDecimal or binaryHex converter

Which form to use: hex or Base64

Neither form is more correct than the other, and software accepts one or the other by convention. Use hex when people have to read, compare or type the value: it is easy to find the first differing digit, every byte is two characters and case-insensitive. Use Base64 when the value has to be short or has to travel in a text field: it is a third larger than the data rather than twice as large. The choice is usually dictated by the other end, and the converter exists so that you do not have to do it by hand.

Questions about converting Base64 to hex

How do I convert Base64 to hex?

Decode the Base64 to bytes and write each byte as two hex digits. The converter does both steps. 3q2+7w== is the four bytes DE AD BE EF, so its hex is DEADBEEF.

Why is the hex string longer than the Base64 string?

Hex needs two characters per byte and Base64 needs about 1.33. A SHA-256 digest of 32 bytes is 64 hex digits and 44 Base64 characters. For short strings the padding in Base64 narrows the gap.

Can I convert Base64 to hex if the string has no padding?

Yes. Missing = signs are restored when the length allows it, and the tool reports that it did so. A length that leaves a remainder of 1 after dividing by 4 cannot be decoded and is reported as an error.

What is the difference between Base64 to hex and hex to text?

Base64 to hex gives the bytes in hexadecimal notation and makes no assumption about what they mean. Hex to text reads the bytes as characters in an encoding. A hash or key is bytes that are not text, so hex is the useful view for it.

Does hex to Base64 use the same tool?

Yes. Swap reverses the direction: the hex output becomes the input of the hex to Base64 conversion, with a choice of the standard or URL-safe alphabet.