Base64 in HTTP Basic Authentication — How It Works
Table of Contents
Every time you log in to a web service that uses HTTP Basic Authentication, your username and password are Base64-encoded and sent in the request header. This is a well-defined standard — not a random implementation choice — and it has important security implications that every developer should understand.
This guide explains exactly how Basic Auth uses Base64, how to construct and decode Authorization headers, and why this scheme is only safe over HTTPS.
How Basic Auth Encodes Credentials
The HTTP Authorization header for Basic authentication follows a precise format defined in RFC 7617:
- Combine username and password with a colon separator:
username:password - Base64-encode the combined string
- Prefix with
Basic(with a space) - Send in the Authorization header
Example — credentials admin:MyP@ssw0rd:
# Step 1: combine admin:MyP@ssw0rd # Step 2: Base64 encode YWRtaW46TXlQQHNzdzByZA== # Step 3+4: full header Authorization: Basic YWRtaW46TXlQQHNzdzByZA==
You can verify this yourself: paste YWRtaW46TXlQQHNzdzByZA== into the Base64 decoder and you will see admin:MyP@ssw0rd — exactly as entered.
Constructing Basic Auth Headers in Code
When calling APIs that use Basic Auth, you often need to construct the header yourself:
# curl — built-in support
curl -u username:password https://api.example.com/endpoint
# curl — manual header
CREDENTIALS=$(echo -n "username:password" | base64)
curl -H "Authorization: Basic $CREDENTIALS" https://api.example.com/endpoint
# JavaScript (fetch)
const credentials = btoa('username:password');
fetch('https://api.example.com/endpoint', {
headers: { 'Authorization': 'Basic ' + credentials }
});
# Python (requests library)
import requests
response = requests.get(url, auth=('username', 'password'))
# requests handles the Base64 encoding automatically
Note the -n flag in the bash example — this prevents echo from adding a newline character at the end of the string, which would corrupt the encoded output.
Decoding a Basic Auth Header to Inspect Credentials
To decode a Basic Auth header, strip the Basic prefix and decode the remaining Base64 string. The result is the username and password separated by a colon.
Using our free Base64 decoder: paste the Base64 portion (everything after "Basic ") and click Decode. You will immediately see the credentials in plaintext.
This is exactly why Basic Auth is not secure over plain HTTP. Any network device between the client and server — routers, proxies, Wi-Fi access points — can see the Authorization header, decode the Base64, and obtain the username and password in seconds. The Base64 encoding provides no confidentiality whatsoever; it is simply a formatting convention for the protocol.
Basic Auth Is Only Safe Over HTTPS
Basic Auth credentials are effectively sent in plaintext (Base64 is trivially reversible). The only thing that makes Basic Auth secure is the transport layer — HTTPS encrypts the entire HTTP request, including the Authorization header, between the client and server.
Rules for using Basic Auth safely:
- Always use HTTPS. Never use Basic Auth over HTTP in production.
- Use strong credentials. Since the credentials are re-sent on every request, they should be long, randomly generated API keys or passwords — not human-memorable ones.
- Consider API keys instead. For machine-to-machine authentication, using long random API keys in the Authorization header provides the same security with better auditability and the ability to rotate individual keys without changing the password.
- Do not log Authorization headers. Server and proxy logs that include full HTTP headers will capture Base64-encoded credentials. Strip or redact Authorization headers from logs.
Testing and Debugging Basic Auth Headers
When debugging API authentication issues, it helps to decode the Authorization header being sent to verify the credentials are correct. Common problems:
- Wrong character in Base64 — a colon in the password is allowed, but a colon in the username is not (it will be treated as the separator). Use a different delimiter or switch to Bearer token auth.
- Extra whitespace — a trailing space or newline in the username or password will be included in the encoded string. The server will see a different value than you intended. Trim inputs before encoding.
- Special characters — Base64 handles any byte sequence, so special characters in passwords encode correctly. The issue is usually at the server side, which may not accept certain characters in credentials.
To quickly verify: take your credentials, encode them with our free tool, and compare the result character-by-character to what your application is sending. Paste the decoded version back to see if it matches what you intended to send.
Try It Free — No Signup Required
Runs 100% in your browser. No data is collected, stored, or sent anywhere.
Open Free Base64 Encoder/DecoderFrequently Asked Questions
Is Base64 in HTTP Basic Auth a security measure?
No. Base64 encoding provides zero security — it is trivially reversible by anyone. Basic Auth is secure only because HTTPS encrypts the entire HTTP request including headers. Without HTTPS, Basic Auth credentials are effectively sent in plaintext.
Can I use any separator besides colon in Basic Auth credentials?
No. RFC 7617 specifies that the username and password are separated by a colon. If your password contains a colon, only the first colon is treated as the separator — everything after it is the password. Usernames cannot contain colons.
What is the difference between Basic Auth and Bearer token auth?
Basic Auth sends username and password (Base64-encoded) on every request. Bearer token auth sends an opaque token (typically a JWT) that was obtained from an authentication endpoint. Bearer tokens can be scoped, time-limited, and revoked individually without changing the underlying password.

