Codificação/Decodificação Base64
Codifique texto ou arquivos em Base64 e decodifique strings Base64 de volta em texto ou arquivos, inteiramente no navegador. Ele roda inteiramente no seu navegador — nenhum dado é enviado para nenhum servidor, nenhuma conta é necessária e é totalmente gratuito.
The Complete Guide to Base64 Encoding and Decoding
Base64 is one of the most quietly pervasive technologies on the internet. If you have ever embedded an image in a CSS file, sent an email attachment, handled authentication tokens, or worked with any web API, you have almost certainly encountered Base64 encoding — often without realizing it. In this comprehensive guide, we demystify Base64, explaining how it works, where it is used, and why it remains an essential tool for every developer.
What is Base64 and Why Does It Exist?
Computers fundamentally communicate in binary — sequences of 0s and 1s organized into bytes. However, many older text-based protocols (like SMTP for email, or HTTP in its early forms) were designed to handle only 7-bit ASCII text. When you try to transmit raw binary data (like an image file or a compiled program) through a channel designed only for ASCII text, the bytes that fall outside the printable ASCII range get mangled or stripped entirely.
Base64 solves this problem by converting arbitrary binary data into a safe set of 64 printable ASCII characters: the uppercase letters A-Z, lowercase letters a-z, digits 0-9, and the symbols + and / (with = used as padding). This guarantees that the encoded data can pass through any text-based system without corruption.
How Does Base64 Encoding Work?
The encoding process is elegant and systematic:
- Group bytes into triplets: Take the raw binary input and group the bytes into sets of 3 (24 bits total).
- Split into four 6-bit groups: Each 24-bit triplet is split into four 6-bit groups (since 2⁶ = 64, each group maps to one of the 64 characters).
- Look up the character: Each 6-bit value (0–63) is mapped to its corresponding Base64 character using the Base64 alphabet.
- Padding: If the input is not a multiple of 3 bytes, one or two
=characters are appended as padding to ensure the output length is a multiple of 4.
The result: every 3 bytes of input produce exactly 4 Base64 characters of output, explaining the ~33% size overhead inherent in Base64 encoding.
Where is Base64 Used in the Real World?
1. Email Attachments (MIME)
The MIME (Multipurpose Internet Mail Extensions) standard uses Base64 to encode binary file attachments — images, PDFs, and documents — so they can be safely transmitted as part of a plain-text email message. When you attach a file to a Gmail message, your email client Base64-encodes it before sending.
2. Embedding Images in HTML and CSS
Instead of serving a separate image file (which requires a separate HTTP request), you can embed small images directly into HTML or CSS as a Base64 data URI:
<img src="data:image/png;base64,iVBORw0KGgoAAAANS..." />
This is useful for small icons, loading spinners, and critical above-the-fold images to eliminate render-blocking requests.
3. HTTP Basic Authentication
When a browser sends HTTP Basic Auth credentials, it Base64-encodes the username:password string and sends it in the Authorization header: Authorization: Basic dXNlcjpwYXNz. Importantly, Base64 is encoding, not encryption — it is trivially reversible and provides zero security by itself. Always use HTTPS when transmitting Basic Auth credentials.
4. JSON Web Tokens (JWT)
JWTs consist of three Base64url-encoded segments separated by dots: the header, the payload (claims), and the signature. The "url-safe" variant replaces + with - and / with _ so the token can be safely included in URLs and HTTP headers without URL-encoding.
5. Cryptographic Outputs
Many cryptographic operations (hashing, encryption, digital signatures) produce raw binary output. Base64 is the standard way to represent these outputs as printable strings in configuration files, databases, and API responses.
Base64 vs. URL-Safe Base64
Standard Base64 uses characters (+ and /) that have special meaning in URLs. URL-safe Base64 (also called Base64url) substitutes these with - and _, making the encoded string safe to use in URL query parameters and path segments without requiring percent-encoding.
Security Reminder
Base64 is an encoding scheme, not an encryption scheme. Anyone who receives a Base64-encoded string can decode it instantly. Never use Base64 as a method of securing sensitive data. For actual security, use proper encryption (AES-256) or cryptographic hashing (SHA-256).
Use our free, private Base64 Encoder/Decoder to quickly encode text, decode API tokens, inspect JWTs, and work with data URIs — all processed entirely in your browser.
Como usar a Codificação/Decodificação Base64
- 1
Choose encode or decode
Select Encode to convert plain text to Base64, or Decode to convert a Base64 string back to text.
- 2
Enter your input
Paste the text or Base64 string you want to convert into the input area.
- 3
Convert and copy
Click Encode or Decode, then copy the output to your clipboard.
Perguntas Frequentes
What is Base64 encoding?
Base64 is a binary-to-text encoding scheme that represents binary data using 64 printable ASCII characters (A-Z, a-z, 0-9, +, /). It is widely used to embed binary data in text-based formats like JSON, XML, HTML, and email.
Why does Base64 make data larger?
Base64 encoding expands data by approximately 33% because every 3 bytes of input become 4 characters of output. This is the expected overhead and is fine for transmission purposes.
What is the difference between Base64 and URL-safe Base64?
Standard Base64 uses + and / characters which are special in URLs. URL-safe Base64 replaces these with - and _ so the encoded string can be safely used in URLs without encoding.
Can this tool handle Unicode/emoji characters?
Yes. The tool uses TextEncoder/TextDecoder to properly handle UTF-8 Unicode text including emoji, Chinese, Arabic, and all other character sets before encoding to Base64.
Is my data sent anywhere?
No. Base64 encoding and decoding use the built-in browser functions (btoa/atob) combined with TextEncoder. Nothing leaves your browser.