HTTP · 7 min read

The Basic auth header, explained.

HTTP Basic authentication sends a username and password with every request, Base64-encoded in one header. It's simple, widely supported and easy to get subtly wrong. This guide covers the exact format from RFC 7617, working examples, the character-encoding trap, and when not to use it.

Updated 9 November 2026

Quick answer

The header is Authorization: Basic <credentials>, where the credentials are the Base64 encoding of username:password. For user Aladdin and password open sesame (the example in RFC 7617) it is Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==. Base64 is not encryption: anyone who sees the header can decode the password, so only send it over HTTPS. Build or decode one with the Basic Auth header generator.

The format

  1. Join the username, a single colon and the password: Aladdin:open sesame.
  2. Turn that text into bytes. Use UTF-8 (more on this below).
  3. Base64-encode the bytes: QWxhZGRpbjpvcGVuIHNlc2FtZQ==.
  4. Send it as Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==.

The scheme name Basic is case-insensitive, and there is exactly one space before the credentials. The Base64 is standard (with +, / and =), on one line.

Decode this example →

The colon rule

The first colon separates the username from the password, so the RFC makes a username containing a colon invalid. A password can contain colons: everything after the first colon belongs to it. alice:p:ss:word is user alice with password p:ss:word, and decoders must split on the first colon only.

When decoding

Split with a limit: decoded.split(":", 1) in Python, indexOf(":") in JavaScript. A plain split(":") truncates any password containing a colon.

How the server asks for it

A protected resource answers an unauthenticated request with 401 Unauthorized and a challenge:

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic realm="Staging", charset="UTF-8"

realm is required and names the protected area; browsers show it in their login prompt. charset is optional, and its only allowed value is UTF-8. The client then retries with the Authorization header. Wrong credentials get another 401. A 403 Forbidden means the credentials were accepted but that user isn't allowed in.

For a proxy, the same scheme uses 407 Proxy Authentication Required, Proxy-Authenticate and Proxy-Authorization.

Examples

curl

curl -u 'Aladdin:open sesame' https://api.example.com/
# sends: Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==

curl -u Aladdin https://api.example.com/    # prompts for the password instead

JavaScript (fetch)

const creds = new TextEncoder().encode("Aladdin:open sesame");
const b64 = btoa(String.fromCharCode(...creds));       // UTF-8 safe
await fetch("https://api.example.com/", {
  headers: { Authorization: `Basic ${b64}` },
});

Python (requests)

import requests

requests.get("https://api.example.com/", auth=("Aladdin", "open sesame"))

# Non-ASCII password? Pass bytes so requests sends UTF-8 (see below):
requests.get("https://api.example.com/", auth=("test".encode(), "123£".encode("utf-8")))

PowerShell

$pair = "Aladdin:open sesame"
$b64  = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($pair))
Invoke-RestMethod -Uri "https://api.example.com/" -Headers @{ Authorization = "Basic $b64" }

Postman and similar clients: pick Basic Auth on the Authorization tab and enter the username and password. The client builds the header for you.

The character-encoding trap

The RFC never fixed a default encoding, so clients differ when the username or password contains anything beyond plain ASCII. With user test and password 123£:

ClientHeader sentEncoding
curl (UTF-8 terminal)Basic dGVzdDoxMjPCow==UTF-8
Python requests, str argumentsBasic dGVzdDoxMjOjLatin-1
Python requests, bytes argumentsBasic dGVzdDoxMjPCow==UTF-8
Browser btoa("test:123£")Basic dGVzdDoxMjOjLatin-1
Browser btoa() with € or emojithrows InvalidCharacterError—

If the server expects UTF-8 (most modern ones do, and charset="UTF-8" in the challenge says so), the Latin-1 version fails to log in even though the password is right. Encode to UTF-8 bytes yourself, as in the examples above. When you decode a header and see � in the password, the client probably sent Latin-1.

Decoding a header you've captured

Take the part after Basic , Base64-decode it, and split on the first colon:

echo 'QWxhZGRpbjpvcGVuIHNlc2FtZQ==' | base64 --decode
# Aladdin:open sesame

Or paste the whole header into the Basic Auth tool (Decode header tab). It runs in your browser, which matters here: a captured header contains a real password, so don't paste it into tools that send it to a server.

Security: what Basic auth does and doesn't do

  • No secrecy on its own. The password is only encoded, so anyone who can read the request can read the password. Over plain HTTP, that means anyone on the network path. Use it only over HTTPS.
  • Sent on every request. There is no session; the credentials go out with every call, so they appear more often in proxies, logs and debugging tools. Strip Authorization from logs.
  • No real logout. Browsers cache the credentials for the realm until the browser is closed.
  • No protection against guessing. Rate-limit failed attempts on the server.
  • Credentials in URLs are out. https://user:pass@host/ is blocked or warned about by modern browsers, and fetch() refuses such URLs with a TypeError. Send the header instead.

Basic auth is fine for internal tools, staging sites, simple APIs and machine-to-machine calls over HTTPS. For user-facing logins or third-party API access, use sessions or tokens (OAuth 2.0 bearer tokens, API keys) that can be scoped and revoked without changing a password. See also Base64 is not encryption.


Published 9 November 2026. Spot an error? Email contactus@base64decode.tools.

Frequently asked

Common questions.

Authorization: Basic followed by one space and the Base64 encoding of username:password. For Aladdin and open sesame that is Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==.

Only when sent over HTTPS. The credentials are Base64-encoded, not encrypted, so anyone who can see the request can decode the password. It is also sent with every request, so keep it out of logs.

Yes. Only the username can't contain a colon, because the first colon separates username from password. Everything after the first colon is the password.

The client probably encoded the credentials as Latin-1 while the server expects UTF-8 (or the reverse). Browser btoa() and Python requests with string arguments use Latin-1. Encode the text to UTF-8 bytes before Base64-encoding it.

Remove the word Basic and the space, Base64-decode the rest, and split the result on the first colon to get the username and password. The Basic Auth tool on this site does it in your browser.

Keep going

Related guides and tools.