# Certificate chains and intermediates explained

> A certificate chain links your server's leaf certificate through one or more intermediate certificates to a root certificate that clients already trust, and the server must send everything except the root.

URL: https://levelrail.com/learn/domains-https/certificate-chains-and-intermediates/
Updated: 2026-11-27

When a browser opens your site, it does not just look at one certificate. It builds a chain from your server's certificate up to a root certificate it already trusts. The server must send the pieces in between. Getting this wrong produces the confusing situation where the padlock looks fine on your laptop and an API client or an older device refuses the connection. A [TLS certificate](https://levelrail.com/learn/glossary/#tls-certificate)) is only useful when the whole chain can be verified.

## How it works

A chain has three kinds of certificate:

1. The leaf (also called the end entity or server certificate). It names your domain and holds your public key. This is the one you request.
2. One or more intermediates. These are certificates a [certificate authority](https://levelrail.com/learn/glossary/#certificate-authority)) uses to sign leaves. The CA keeps its root key offline and signs day to day certificates with intermediates, which limits the damage if an issuing key is exposed.
3. The root. A self signed certificate that clients ship in their trust store, the list of CAs the operating system or browser trusts.

Each certificate names its issuer and carries a signature from it. The client checks that the leaf was signed by the intermediate, that the intermediate was signed by the root, that the root is in its trust store, that none are expired, and that the name matches the site. The root is never sent, because the client has to already have it for the check to mean anything.

The chain is built from what the server sends during the TLS handshake. If the server forgets the intermediate, the client has a leaf signed by someone it has never heard of.

## Serve fullchain.pem, not cert.pem

[Certbot](https://levelrail.com/learn/glossary/#certbot)) writes several files per certificate under `/etc/letsencrypt/live/example.com/`:

| File | Contents |
| --- | --- |
| cert.pem | The leaf only |
| chain.pem | The intermediate(s) only |
| fullchain.pem | The leaf followed by the intermediate(s) |
| privkey.pem | The private key |

Servers should use fullchain.pem for the certificate and privkey.pem for the key. In nginx:

```nginx
ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
```

Using cert.pem here is the classic mistake that produces an incomplete chain. Reload after changing it with `sudo nginx -t && sudo systemctl reload nginx`. Tools like Caddy and platforms that manage certificates for you handle this automatically. See [Nginx reverse proxy with certbot](https://levelrail.com/learn/domains-https/nginx-reverse-proxy-with-certbot/)) and [Automatic HTTPS with Caddy](https://levelrail.com/learn/domains-https/automatic-https-with-caddy/)).

## Inspect the chain a server sends

Use openssl to see exactly what your server presents:

```bash
openssl s_client -connect example.com:443 -servername example.com -showcerts </dev/null
```

The `-servername` flag sends the site name (SNI) so a server hosting many sites returns the right certificate. Near the top, a block starting with `Certificate chain` lists numbered entries. Each entry has a line starting with `s:` (subject) and one starting with `i:` (issuer). A healthy chain looks like this in outline:

```text
Certificate chain
 0 s:CN = example.com
   i:C = US, O = <CA name>, CN = <Intermediate name>
 1 s:C = US, O = <CA name>, CN = <Intermediate name>
   i:C = US, O = <CA name>, CN = <Root name>
```

Entry 0's issuer matches entry 1's subject. That link is what you verify. If the list stops at entry 0 and its issuer is an intermediate, the server did not send the intermediate. At the end of the output look for the line starting with `Verify return code:`. A value of `0 (ok)` means openssl built a trusted path. Another value, such as 21 with the text "unable to verify the first certificate", signals a chain problem. For reading other fields see [Inspect a TLS certificate with openssl](https://levelrail.com/learn/domains-https/inspect-a-tls-certificate-with-openssl/)).

To check a certificate file on disk before deploying it:

```bash
openssl verify -untrusted chain.pem cert.pem
```

## Why some clients hide the problem

If the server omits the intermediate, behavior depends on the client:

- Some browsers keep intermediates they saw on other sites, or can download the missing one from a URL inside the leaf. The site appears fine for them.
- curl, many programming language HTTP libraries, mobile apps, webhooks senders and monitoring tools usually do neither, and fail with a verification error.

So "it works in my browser" does not prove the chain is complete. Test with `openssl s_client` or `curl -I https://example.com` from a clean machine, and with an online checker if you like. Do not fix this by disabling verification in your client (`curl -k` or similar). That hides the error and removes the protection TLS gives.

## Check it worked

```bash
openssl s_client -connect example.com:443 -servername example.com </dev/null 2>/dev/null | grep -E "Verify return code|depth"
curl -sI https://example.com | head -n 1
```

You want `Verify return code: 0 (ok)` and a normal HTTP status line from curl. Also confirm the leaf names your domain and has not expired with `openssl x509 -noout -subject -dates`.

## Edge cases and gotchas

- **Cross signed chains:** CAs sometimes offer alternative chains, for example to support older roots. Which chain you receive depends on the CA and client settings.
- **Intermediates rotate:** a CA can change its intermediates over time. Automatic renewal usually fetches the new chain, but pinned copies of an old chain go stale.
- **Wrong file order:** a fullchain file must have the leaf first, then the intermediate. A reversed order can fail on strict clients.
- **SNI matters:** without `-servername`, a multi-site server may hand back a default certificate and mislead your test.
- **Proxy in front:** if a CDN or load balancer terminates TLS, its certificate is what clients see, not the one on your origin.
- **Old devices:** very old operating systems may lack a newer root in their trust store, regardless of how you configure the server.

## Troubleshooting

| Symptom | Likely cause | Fix |
| --- | --- | --- |
| curl: unable to get local issuer certificate | The server did not send the intermediate | Point the server at fullchain.pem and reload |
| Browser fine, API client fails verification | Browser cached or fetched the intermediate | Fix the chain on the server, retest with openssl |
| Verify return code is not 0 | Missing or wrong intermediate, or an expired certificate | Read the message, replace the chain, check dates |
| Certificate name does not match | Wrong certificate served for this hostname | Check SNI and the server block, reissue with the name |
| Works on new phones, fails on old ones | Old trust store lacks the root | Use a chain that old clients support, or update the device |
| Chain correct on disk, wrong on the wire | Server not reloaded or another service answers | Reload the server and confirm which process owns port 443 |

## Quick reference

```bash
openssl s_client -connect example.com:443 -servername example.com -showcerts </dev/null
openssl verify -untrusted chain.pem cert.pem
sudo nginx -t && sudo systemctl reload nginx
```

```text
ssl_certificate      fullchain.pem   leaf + intermediate(s)
ssl_certificate_key  privkey.pem     private key, never share
```

## Related lessons

- [Inspect a TLS certificate with openssl](https://levelrail.com/learn/domains-https/inspect-a-tls-certificate-with-openssl/)): read subject, issuer and dates.
- [How TLS certificates are issued](https://levelrail.com/learn/domains-https/how-tls-certificates-are-issued-acme/)): where the chain comes from.
- [Nginx reverse proxy with certbot](https://levelrail.com/learn/domains-https/nginx-reverse-proxy-with-certbot/)): the working setup with fullchain.pem.
- [Renew Let's Encrypt certificates](https://levelrail.com/learn/domains-https/renew-lets-encrypt-certificates/)): why a reload is needed after renewal.
- [Fix Let's Encrypt certificate errors](https://levelrail.com/learn/troubleshooting/fix-lets-encrypt-certificate-errors/)): other certificate failures.

## Next

Continue with [HSTS explained](https://levelrail.com/learn/domains-https/hsts-explained/)).

## Frequently asked questions

### What is the difference between cert.pem and fullchain.pem?

With certbot, cert.pem is only your own (leaf) certificate. fullchain.pem is the leaf followed by the intermediate certificate(s). Servers should be configured with fullchain.pem.

### What is an intermediate certificate?

A certificate issued by a root CA that is then used to sign end certificates. It keeps the root key offline and lets the CA rotate issuing keys.

### Do I need to send the root certificate?

No. The client already trusts the root through its trust store, so the server sends the leaf and the intermediates only.

### What does 'unable to get local issuer certificate' mean?

The client could not build a path from the server's certificate to a root it trusts, most often because the server did not send the intermediate certificate.


## Sources

- [Let's Encrypt, chain of trust](https://letsencrypt.org/certificates/)
- [RFC 5280, Internet X.509 Public Key Infrastructure Certificate and CRL Profile](https://www.rfc-editor.org/rfc/rfc5280)
