Base64, URL and HTML encoder and decoder

Encode or decode Base64, URL-safe Base64, URL percent-encoding, HTML entities, hex bytes and Unicode code points, with UTF-8 and UTF-16 byte counts.

업데이트 검증한 예제: 17

시도하기
결과
Q2Fmw6kgJiBjcsOobWUsIDUg4oKs
결과: Q2Fmw6kgJiBjcsOobWUsIDUg4oKs
Characters (code points)
17
UTF-8 bytes
21
UTF-16 code units
17
Result length
28characters

17 characters become 21 UTF-8 bytes; as Base64 they take 28 characters, 1.33 per byte.

크기

Characters17UTF-8 bytes21UTF-16 bytes34Base64 output28

UTF-8 bits of the first characters

“C” U+0043 → 43
0
1
0
0
0
0
1
1
“a” U+0061 → 61
0
1
1
0
0
0
0
1
“f” U+0066 → 66
0
1
1
0
0
1
1
0
“é” U+00E9 → c3 a9
1
1
0
0
0
0
1
1
1
0
1
0
1
0
0
1
계산 방법 S
  1. Encode the text as UTF-8

    17 characters → 21 bytes.

  2. Regroup 8-bit bytes into 6-bit indices

    First group: 43 61 66 → 010000 110110 000101 100110 → 16, 54, 5, 38 → “Q2Fm”.

  3. Output length

    4⌈213⌉=284 \left\lceil \frac{21}{3} \right\rceil = 28

Base64, URL and HTML encoder and decoder 소개

Every scheme here starts from the text's UTF-8 bytes. Base64 regroups each 3 bytes into four 6-bit values drawn from a 64-character alphabet (RFC 4648), so the output is 4 × ⌈n ÷ 3⌉ characters. Percent-encoding writes every byte outside A–Z, a–z, 0–9 and - . _ ~ as %XX (RFC 3986), HTML escaping replaces & < > " and ' with character references, and hex writes two digits per byte.

Developers use it to put binary data in JSON or email, build query strings, read JWTs and track down character-set problems. The default, "Café & crème, 5 €", is 17 characters but 21 UTF-8 bytes, because é and è take 2 bytes each and € takes 3, and its Base64 form is 28 characters.

A decoding error names the bad character and its position, and bytes that aren't valid UTF-8 show as U+FFFD (�).

계산 예제

Base64 of “foob” (two padding characters)

Encoding
Base64
Direction
Encode
텍스트
foob
결과
Zm9vYg==
UTF-8 bytes
4
Result length
8 characters

검증 출처: RFC 4648 §10 test vectors; Python 3.8 base64.b64encode(b'foob') and len() of input and output

Base64 of an empty string

Encoding
Base64
Direction
Encode
결과
UTF-8 bytes
0
Result length
0 characters

검증 출처: RFC 4648 §10: BASE64("") = ""

URL-safe Base64 without padding

Encoding
Base64 (URL-safe)
Direction
Encode
텍스트
<<???>>
결과
PDw_Pz8-Pg
Result length
10 characters

검증 출처: Python 3.8 base64.urlsafe_b64encode(b'<<???>>').rstrip(b'=') (10 characters); the standard alphabet gives PDw/Pz8+Pg==

Decode Base64 to Chinese text

Encoding
Base64
Direction
Decode
Encoded text
5L2g5aW9IOS4lueVjA==
결과
你好 世界
Characters (code points)
5
UTF-8 bytes
13
UTF-16 code units
5

검증 출처: Python 3.8 base64.b64decode('5L2g5aW9IOS4lueVjA==').decode('utf-8'); len() of the text, its UTF-8 bytes and its UTF-16-LE bytes ÷ 2

자주 묻는 질문

Why does Base64 make data about 33% larger?

Base64 carries 6 bits in each output character against 8 bits in each input byte, so every 3 bytes become 4 characters, a ratio of 4 to 3, plus up to 2 = padding characters at the end. 21 bytes become 28 characters, and 1 MB of binary becomes about 1.33 MB. MIME email (RFC 2045) also breaks the output into lines of at most 76 characters, which adds a little more.

What is the difference between Base64 and Base64URL?

Base64URL (RFC 4648 §5) replaces the two characters that clash with URLs and file names, + and /, with - and _, and usually drops the = padding. JSON Web Tokens (RFC 7519) use it for all three of their parts. The text <<???>> is PDw/Pz8+Pg== in standard Base64 and PDw_Pz8-Pg in the URL-safe form, 10 characters instead of 12.

Is Base64 a form of encryption?

No. Base64 is a reversible encoding with no key, so anyone can decode it in one step; it only makes binary data safe to carry as text. HTTP Basic authentication (RFC 7617), for example, sends user:password in Base64, which is why it is only safe over HTTPS. To protect data, encrypt it first, for example with AES-256, and then Base64-encode the ciphertext if it must travel as text.

Should a space be URL-encoded as %20 or +?

Both appear, in different places. RFC 3986, which governs URLs, encodes a space as %20, while HTML form submissions (application/x-www-form-urlencoded) write it as +. So a+b in a form's query string means a b, but in a URL path the + is a literal plus. JavaScript's encodeURIComponent gives %20, and Python's urllib.parse.quote_plus gives +.

How many bytes does a character take in UTF-8?

One to four. Code points below U+0080 (ASCII) take 1 byte, those up to U+07FF take 2 (é, ñ, Greek, Cyrillic), those up to U+FFFF take 3 (€ and most Chinese characters) and the rest take 4, including emoji such as 😀 (U+1F600). So A€😀 is 3 characters, 8 UTF-8 bytes and 4 UTF-16 code units, because 😀 needs a surrogate pair in UTF-16 (RFC 3629).

“Base64, URL and HTML encoder and decoder”의 정확도는 어느 정도인가요?

정확도는 입력값과 계산 방법의 가정에 따라 달라집니다. 십진 연산은 유효숫자 50자리를 사용하지만, 추정값·수치해석 방법·원본 데이터의 정밀도는 더 낮을 수 있습니다. 표시값을 반올림해도 이러한 한계는 사라지지 않습니다. 독립적인 출처의 풀이와 대조한 계산 예시: 17. 예를 들어 “Base64 of “foob” (two padding characters)”은 RFC 4648 §10 test vectors; Python 3.8 base64.b64encode(b'foob') and len() of input and output와 대조해 확인합니다.

이 계산 방법의 출처는 무엇인가요?

RFC 4648 — The Base16, Base32, and Base64 Data Encodings; RFC 3986 §2 — URI characters and percent-encoding; RFC 3629 — UTF-8, a transformation format of ISO 10646; WHATWG HTML — Named character references; The Unicode Standard, §3.9 Unicode encoding forms.

이 계산기 소개

Base64 length=4⌈n3⌉hex length=2nn=UTF-8 bytes\begin{aligned} \text{Base64 length} &= 4\left\lceil \frac{n}{3} \right\rceil \\ \text{hex length} &= 2n \\ n &= \text{UTF-8 bytes} \end{aligned}

출처

  1. RFC 4648 — The Base16, Base32, and Base64 Data Encodings
  2. RFC 3986 §2 — URI characters and percent-encoding
  3. RFC 3629 — UTF-8, a transformation format of ISO 10646
  4. WHATWG HTML — Named character references
  5. The Unicode Standard, §3.9 Unicode encoding forms

출처와 대조하여 검증

이 계산기에는 독립적인 출처에서 답을 얻은 계산 예제가 17개 있습니다. 테스트 모음에서 실행되며 여기에서도 실행할 수 있습니다.

관련 계산기