RTF file format
Rich Text Format, a cross-platform formatted-text document format.
- MIME type
- application/rtf
- Extensions
- .rtf
- Category
- Documents
Magic-number signature
| 0x00000000 | 7B5C72746631 | {\rtf1 | '{\rtf1' header |
About the RTF format
RTF is a document format made entirely of printable ASCII: braces open and close groups, backslash-prefixed control words carry the formatting, and everything else is literal text. That makes it the one word-processing format you can read, diff and repair in a text editor, and the one that survives being pasted through a mail client. The price is size and fidelity — an RTF with images is enormous, because every byte of every picture is written out as hexadecimal digits.
Header layout, byte by byte
| Offset | Length | Field | Meaning |
|---|---|---|---|
| 0 | 1 | Opening group brace | The byte 7B, '{'. The whole document is one group, so this brace is matched by the file's very last byte. Braces nest, and an unbalanced pair is the single most common way an RTF file breaks. |
| 1 | 4 | \rtf control word | The four bytes 5C 72 74 66. A control word is a backslash followed by lowercase letters and an optional numeric parameter; this one names the format itself and must be the first thing inside the outermost group. |
| 5 | 1 | Version digit | The numeric parameter of \rtf, and in every RTF ever released it is the single ASCII character '1'. The specification has reached version 1.9.1 without ever incrementing this digit, so it identifies the format rather than the revision. |
| 6 | variable | Character set control word | The specification requires the character set immediately after the version. \ansi is what you will see essentially always and occupies five bytes; \mac, \pc and \pca are the legacy alternatives and are shorter, which shifts every offset below. |
| 11 | variable | \ansicpg code page | Present at exactly this offset when the charset word was the five-byte \ansi. Its parameter is the Windows code page the document's bytes are in — 1252 for Western European, 936 for Simplified Chinese, 932 for Japanese. Characters outside that page are escaped as \'hh or \uNNNN? instead. |
| variable | variable | \deff, \fonttbl and \colortbl | After the code page come the default font index, then the font table group {\fonttbl ...} and usually a colour table {\colortbl ...}. Their offsets depend on everything above them, but they are always groups and always precede the document body, so a hex dump of the first few hundred bytes shows font names in plain ASCII. |
| -1 | 1 | Closing group brace | The byte 7D, '}', closing the group opened at offset 0. Some writers append a CR LF after it. If the final non-whitespace byte is not a closing brace, the file was truncated — and unlike most formats, you can often repair it by appending the missing braces by hand. |
Telling it apart from its neighbours
| Easily confused with | How to tell |
|---|---|
| Word document (docx) | Not remotely alike at byte level — '{\rtf1' against 50 4B 03 04 — but they are the two formats people mean by 'a Word file that is not a .doc'. Word opens and writes both, and a .docx renamed to .rtf still opens in Word because Word sniffs the bytes. RTF carries no revision history, no comments thread and no embedded fonts, so 'Save as RTF' is a deliberate way of stripping a document down. |
| OLE2 / CFB | The genuinely confusing pair, because both are what a '.doc' can turn out to be. A real Word 97 binary document is a Compound File Binary container starting D0 CF 11 E0; a great many files distributed as .doc are actually RTF, because RTF opens everywhere and the extension was more familiar. Read offset 0 rather than the extension: '{\rtf1' is unambiguous. |
| HTML | Both are markup made of readable ASCII, and both are what a clipboard hands over when you copy formatted text — Windows offers RTF and HTML on the clipboard simultaneously. They are told apart trivially at offset 0, but the practical distinction is that RTF has no external references at all: no linked stylesheet, no remote image, everything is inline, which is why it is the safer of the two to accept from a stranger. |
| Text (UTF-8 with BOM) | An RTF file is technically plain ASCII text, so a naive detector that only checks for printable bytes will call it text — and a text editor will happily open it and show the markup. The distinguishing test is the six-byte prefix; note also that RTF is not allowed to carry a UTF-8 BOM, since the file must begin with the brace, so EF BB BF at offset 0 means the file has been mangled. |
How these files break
- Unbalanced braces. Because groups nest and control words inherit from the enclosing group, one missing '}' means every formatting attribute set inside that group leaks into the rest of the document. The visible symptom is a file that opens fine and renders the second half in the wrong font or entirely bold, with no error message anywhere.
- The wrong code page. If \ansicpg says 1252 and the bytes were actually written in 936, every non-ASCII character renders as mojibake. Not one byte of the file is damaged and the document structure is perfectly intact — the single number at offset 11 is what is wrong, and correcting it repairs the whole document.
- Truncation. An RTF cut short still opens in most word processors, which simply render what they parsed and close the outstanding groups themselves. That leniency is a trap: the document appears complete and is silently missing its last pages. Check that the final non-whitespace byte is '}'.
- A stray backslash in literal text. Backslash, brace and the escape sequences are the only special characters, so a writer that forgets to escape a literal '\' or '{' turns user text into a control word. The result is text vanishing from the rendered output while remaining plainly visible in a hex dump.
- Line-ending translation, which for once is harmless. RTF ignores CR and LF outside of control words, so the text-mode transfer that destroys a PNG or a ZIP leaves an RTF perfectly readable. It is one of the few binary-adjacent formats that genuinely survives an ASCII-mode FTP.
Where the format stands today
RTF is a fallback format, and it is still the best one available. Nobody chooses it to author in, but it remains the reliable answer to 'send me something with formatting that will open anywhere', because every word processor written since 1987 reads it and none of them need a plugin. It survives in three places in particular: as the clipboard's formatted-text flavour on Windows and macOS, so every copy-paste of styled text between applications is an RTF round trip; as the export format for legal and government systems that must not depend on a vendor; and as the safe intake format for documents from untrusted sources, since RTF has no macros, no scripting and no external references. Microsoft stopped developing the specification at version 1.9.1 in 2008 and Word's own RTF converter has been deprecated, so it is frozen rather than evolving. For anything new, .docx carries far more fidelity at a fraction of the size — an RTF with a handful of photographs runs to tens of megabytes because images are stored as ASCII hexadecimal, doubling their size before compression, of which there is none.
Open RTF files on this site
Every one of these runs in your browser — the file never leaves your machine.
Related formats
Formats that are easy to confuse with RTF — compare their leading bytes.
| Format | First bytes | Extension |
|---|---|---|
| Word document (docx) | 50 4B 03 04 | .docx |
| OLE2 / CFB | D0 CF 11 E0 A1 B1 | .doc |
| 25 50 44 46 2D |