# 511 Network Authentication Required

> https://http-status.org/docs/511

**Family:** 5xx Server Error

## Rationale

Client needs to authenticate to gain network access.

## In Plain Terms

You need to log in to the WiFi or network first before you can access any websites.

## Description

The HTTP 511 Network Authentication Required status code indicates that the client needs to authenticate to gain network access. This is typically used by captive portals to require authentication before granting access to the broader internet.

## Server Perspective

### Usage
- Return 511 from an intercepting proxy or captive portal, not from a normal origin application
- Use it to signal that the client must authenticate to the network before the original request can proceed
- WiFi captive portals
- Hotel or airport network login
- Corporate network authentication
- Public network access control

### Implementation
- Include clear instructions or a link to the captive-portal login flow in the response body
- Keep the response distinct from origin authentication so non-browser clients do not mistake it for a normal 401 challenge

### Common Headers
- No status-specific authentication challenge header is required; provide navigation to the login or acceptance flow in the response body or portal metadata

### Body
- A body is recommended; explain the captive-portal requirement and link to the page where the user can authenticate or accept terms

### Pitfalls
- Do not use 511 for website or API authentication; use 401 or 403 for origin-application auth flows
- Do not let the response look like it came from the target origin server when it is really generated by the network
- Website authentication (use 401 Unauthorized)
- Proxy authentication (use 407 Proxy Authentication Required)
- Application-level auth (use 401 or 403)

## Client Perspective

### Pitfalls
- Do not treat 511 as proof that the origin application rejected the request
- Do not cache portal content as if it were the requested origin resource

## Examples

### WiFi captive portal

Must authenticate with WiFi portal before accessing internet

**Request:**
```
GET https://api.example.test/captive-portal-check
```

**Response:**
```
511 Network Authentication Required
Content-Type: text/html; charset=utf-8

<!doctype html>
<html><body>Network login required.</body></html>
```

## Related Codes

- [401 Unauthorized](/docs/401.md)
- [407 Proxy Authentication Required](/docs/407.md)

