401 4xx Client error RFC 3261
SIP 401 Unauthorized
The request needs user authentication. Sent by registrars and user agents with a WWW-Authenticate challenge. The client should resend with credentials.
401 Unauthorized is a challenge, not necessarily a failure. A registrar or user agent that wants proof of identity answers the first request with 401 and a WWW-Authenticate header holding a realm and a one-time nonce. The client repeats the request with an Authorization header containing a digest hash of its username, password and that nonce. A healthy registration runs REGISTER, 401, REGISTER, 200 OK.
You meet 401 most often when phones and softphones register to a PBX or hosted platform, and from Asterisk when an inbound INVITE does not match any configured endpoint. Some carriers also challenge outbound calls with 401 instead of 407.
It only becomes a problem when it repeats. A second 401 straight after a request that carried credentials means the digest was rejected: wrong password, wrong auth username, an unexpected realm, or an algorithm the client cannot handle. A phone shows "registration failed"; on an inbound trunk, the call fails before it rings.
What it looks like in a SIP trace
Phone -> Registrar : REGISTER sip:pbx.example.com SIP/2.0 (CSeq 1)
Registrar -> Phone : SIP/2.0 401 Unauthorized
WWW-Authenticate: Digest realm="pbx.example.com", nonce="5f2a9c71e0b84d3a", algorithm=MD5, qop="auth"
Phone -> Registrar : REGISTER sip:pbx.example.com SIP/2.0 (CSeq 2)
Authorization: Digest username="2001", realm="pbx.example.com", nonce="5f2a9c71e0b84d3a",
uri="sip:pbx.example.com", response="3f6d1e0b9a72c4e8d5a1b6c0f7e2d913", algorithm=MD5,
qop=auth, nc=00000001, cnonce="0a4f113b"
Registrar -> Phone : SIP/2.0 200 OK <- credentials accepted
(or) SIP/2.0 401 Unauthorized <- digest rejected: check auth user and secret
Example values only. Your headers, addresses and numbers will differ.
Common causes
- Normal first step of digest authentication on REGISTER.
- Wrong username, password, or auth username (auth ID).
- Realm mismatch between client and server.
How to diagnose it
- Count the 401s. One 401 followed by 200 OK is normal; a 401 in reply to a request that already carried an
Authorizationheader means the credentials were rejected. - Compare the
usernamein the Authorization header with the auth username on the server. It often differs from the extension number, and phones label it differently: Auth ID, Register Name or Authenticate ID. - Check that the
realmthe client answers with matches the challenge. Clients with a fixed realm configured can reply with the wrong one. - Look at the
algorithm. Newer servers may offer SHA-256 digests (RFC 8760), and a client that understands only MD5 cannot answer unless MD5 is offered too. - A 401 with
stale=trueonly means the nonce expired, and the client should retry silently. Repeated stale challenges can come from clustered servers that do not share a nonce secret. - A stream of 401s for non-existent extensions from unknown addresses is a scanner guessing passwords; block it and read the toll fraud guide.
How to fix it
- One 401 followed by success is normal. Repeated 401s mean the credentials are wrong.
- Check the auth username separately from the extension number. Many systems use different values.
- Verify realm and clock or nonce settings. Look at the server logs for the reason the digest was rejected.
Platform notes
Asterisk / FreePBX
Asterisk logs rejected digests as Failed to authenticate and an INVITE from an unknown source as No matching endpoint found; both end in 401. If inbound trunk calls get 401, the carrier's IP is probably not matched to the trunk, so check the trunk's match (permit) setting and pjsip show identifies.
OpenSIPS / Kamailio
The script sends the challenge with www_challenge() (or auth_challenge() in Kamailio) after the authorisation check fails. If you store HA1 hashes instead of plain passwords, the hash includes the realm, so changing the domain or realm invalidates every stored hash.
Phones and softphones
Phones keep separate fields for user ID, auth ID and display name. Leaving auth ID blank makes most phones reuse the user ID, which fails where the provider issues a different authentication name.
SIP 401 FAQ
Is SIP 401 an error?
Not by itself. A single 401 is the normal first step of digest authentication. It is a fault only when the client answers the challenge and still gets 401, or never answers it.
What is the difference between 401 and 407?
Both are digest challenges. 401 comes from a registrar or end device with WWW-Authenticate; 407 comes from a proxy with Proxy-Authenticate, and the client must answer with the matching header.
Why does my trunk register but inbound calls get 401?
Registration and inbound calls are checked differently. If the PBX challenges INVITEs from the carrier, it has not recognised the carrier's IP, so it treats the call like an unknown user. Match the carrier's signalling IPs to the trunk.
Related codes
Related guides
SIP Registration Failed? Troubleshooting Checklist
Fix failed SIP registrations step by step: read 401, 403, 404, 408, 423 and 503 replies, then check DNS, ports, NAT, fail2ban bans and Asterisk PJSIP.
Protect Your PBX From Toll Fraud
Protect your PBX from toll fraud with firewall allowlists, fail2ban, strong secrets, dial plan limits, provider spend caps, CDR alerts and an incident plan.