What is Base64 Encoding?
Base64 is a binary-to-text encoding scheme that converts binary data into an ASCII string format using a set of 64 characters: the uppercase letters A–Z, lowercase letters a–z, the digits 0–9, and the symbols + and /, with = used as padding.
The name "Base64" comes from the fact that it uses a 64-character alphabet. Every 3 bytes (24 bits) of binary input are encoded as 4 Base64 characters. This means Base64-encoded data is approximately 33% larger than the original data — a small overhead that is acceptable in most use cases.
Base64 encoding was originally developed for MIME email attachments (defined in RFC 2045) to allow binary files like images and documents to be safely embedded in email messages, which were designed for plain ASCII text. Over the decades, Base64 has become ubiquitous in web development.
It is important to understand that Base64 is an encoding scheme, not encryption. Anyone who receives a Base64-encoded string can trivially decode it. Do not use Base64 alone to secure sensitive information; use proper encryption algorithms for that purpose.
How to Use This Base64 Encoder
- Enter your text: Type or paste any string, JSON payload, credentials, or other text into the left text area.
- Click "Encode to Base64": The tool will immediately return the Base64-encoded representation of your input.
- Copy the encoded string: Use the Copy Output button to copy the result for use in your JWT header, HTTP Authorization header, data URI, or any other destination.
- Use the result: Paste the Base64 string wherever it's needed — in your code, API configuration, or documentation.
This tool uses PHP's built-in base64_encode() function, which correctly handles multi-byte UTF-8 text including characters from non-Latin scripts.
Why is Base64 Encoding Important?
Base64 encoding is used in many critical areas of modern web development and systems programming:
- JSON Web Tokens (JWT): JWTs consist of three Base64URL-encoded parts (header, payload, and signature) joined by dots. Every time you work with JWT authentication, you are working with Base64.
- HTTP Basic Authentication: The
Authorizationheader for Basic Auth is constructed by encodingusername:passwordin Base64. For example:Authorization: Basic dXNlcjpwYXNzd29yZA== - Data URIs: Embedding images, fonts, or other files directly into HTML or CSS uses Base64 data URIs:
src="data:image/png;base64,iVBORw0KGgoAAAA..." - API Credentials: Many cloud services (AWS, Google Cloud, Stripe) use Base64-encoded API keys and secret tokens.
- Email Attachments (MIME): File attachments in emails are Base64-encoded to safely transmit binary data through email infrastructure designed for text.
- Storing Binary Data in JSON/XML: JSON and XML are text formats. Embedding binary data (like images or certificates) requires Base64 encoding.
Base64 Encoding Examples
Input: Hello, World! Output: SGVsbG8sIFdvcmxkIQ==
Input: admin:secretpassword Output: YWRtaW46c2VjcmV0cGFzc3dvcmQ= Usage: Authorization: Basic YWRtaW46c2VjcmV0cGFzc3dvcmQ=
Input: {"user":"alice","role":"admin"}
Output: eyJ1c2VyIjoiYWxpY2UiLCJyb2xlIjoiYWRtaW4ifQ==
Notice the = and == padding at the end of some encoded strings. This padding ensures the output length is always a multiple of 4 characters. To decode Base64 back to its original form, use our Base64 Decoder tool.