Base64 Encode & Decode · Tutorial

How to create a Basic Auth header with Base64

5 min readbeginnerUpdated

Many APIs, webhooks and internal dashboards use HTTP Basic authentication, which expects your username and password joined by a colon and Base64-encoded in an Authorization header. This tutorial walks through building that header correctly, including the details that most often cause a 401 Unauthorized response.

What you need

  • The Base64 Encode & Decode
  • The username and password (or API key and secret) for the service
  • Optionally, a terminal with curl to test the header

Steps

  1. Join the username and password with a colon

    Type the two values into the left box as username:password, with no spaces around the colon. Some services give you an API key and secret instead: use the key as the username and the secret as the password. The sample loaded by Try it is api_user:s3cret-Passw0rd.

  2. Keep the standard Base64 alphabet

    Leave URL-safe and Wrap lines unticked. The HTTP standard for Basic auth uses regular Base64 with +, / and = padding, on a single line. The encoded value appears on the right straight away.

    YXBpX3VzZXI6czNjcmV0LVBhc3N3MHJk
  3. Add the Basic prefix

    The header value is the word Basic, one space, then the encoded string. Press Copy and put it together like this.

    Authorization: Basic YXBpX3VzZXI6czNjcmV0LVBhc3N3MHJk
  4. Test the header

    Send a request with the header to confirm the credentials work. A 200 response means success. A 401 means the server rejected the credentials or the header format.

    curl -H "Authorization: Basic YXBpX3VzZXI6czNjcmV0LVBhc3N3MHJk" \
      https://api.example.com/v1/status
  5. Decode it to double-check

    If something is wrong, paste the encoded part (without Basic ) into Base64 Decode to see exactly what the server receives. Stray spaces or a missing character show up immediately.

Try it yourself

Opens the Base64 Encode & Decode with this tutorial's sample loaded.

Try it now

Common mistakes

A trailing space or newline
Copying credentials from a document often brings a hidden space or line break along, which becomes part of the password. Make sure the left box contains exactly username:password and nothing else.
Using the URL-safe variant
URL-safe Base64 replaces + and / and drops =. Servers expect the standard form, so a password that happens to produce those characters will fail with URL-safe output.
Treating Base64 as protection
Anyone who sees the header can decode the password. Only send Basic auth over HTTPS, and never commit the encoded header to a public repository.

Next steps

Go back to the Base64 Encode & Decode, or keep going with one of these:

Tutorial · 6 min · beginner

How to decode a JWT and read its payload

Decode a JSON Web Token in your browser to see its header and claims, such as user ID, role and expiry time, without sending the token anywhere.

FAQ

Does curl have a shortcut for this?

Yes. curl -u username:password URL builds the same header for you. Encoding it yourself is useful for tools, config files and API clients that ask for the raw header value.

What if my password contains a colon?

That is allowed. Servers split on the first colon only, so the username itself must not contain one.