# .pem MIME Type: application/x-pem-file

> Base64-encoded certificates and keys between -----BEGIN and -----END lines. Unregistered; application/x-pem-file is the convention.

- MIME type: `application/x-pem-file`
- Extensions: .pem
- Content-Type header: `application/x-pem-file`
- Compress in transit: yes
- File signature: `2D 2D 2D 2D 2D 42 45 47 49 4E` (some tools write text before the first BEGIN line)

## Good to know

- The label after `BEGIN` says what's inside: `CERTIFICATE`, `PRIVATE KEY`, `PUBLIC KEY`, `CERTIFICATE REQUEST`. One file can hold several blocks, such as a certificate chain.
- To publish a certificate for download, serve it as DER with `application/pkix-cert` — see [.crt](https://www.devkult.com/mime/crt.md).
- Private keys never belong in a web root. On disk they should be [chmod 600](https://www.devkult.com/chmod/600.md) or [chmod 400](https://www.devkult.com/chmod/400.md); ssh refuses keys that other users can read.

## Server configuration

### nginx (inside the types block in mime.types)

```
application/x-pem-file pem;
```

### Apache (.htaccess or server config)

```
AddType application/x-pem-file .pem
```

### Express

```
res.set("Content-Type", "application/x-pem-file");
```

### Python

```
import mimetypes

mimetypes.add_type("application/x-pem-file", ".pem")
```

### HTML file input

```
<input type="file" accept=".pem,application/x-pem-file">
```

## FAQ

### What is the MIME type for .pem files?

`application/x-pem-file`.

### What Content-Type header should a .pem file be served with?

`Content-Type: application/x-pem-file`. It compresses well, so let the server apply gzip or Brotli.

### How can I tell if a file is really a .pem?

Check its bytes rather than the extension: PEM files start with `2D 2D 2D 2D 2D 42 45 47 49 4E` (`-----BEGIN`) — some tools write text before the first BEGIN line. On the command line, `file --mime-type name.pem` does this for you.

## Related types

- [.crt — application/pkix-cert](https://www.devkult.com/mime/crt.md)
- [.txt — text/plain](https://www.devkult.com/mime/txt.md)

Open the interactive page: https://www.devkult.com/mime/pem