Ogg file format
Ogg container, commonly wrapping Vorbis/Opus audio or Theora video.
- MIME type
- application/ogg
- Extensions
- .ogg, .oga, .ogv
- Category
- Audio
Magic-number signature
| 0x00000000 | 4F676753 | OggS | 'OggS' page capture pattern |
About the Ogg format
Ogg is an open, patent-free streaming container most often carrying Vorbis or Opus audio, widely used in games and open-source software. Every page starts with the capture pattern 'OggS'. That word 'every' is the whole design: an Ogg file is not a header followed by data, it is a chain of self-describing pages, each with its own checksum, sequence number and stream serial, so a decoder can join a live stream mid-flight and a damaged download can be resynchronised by scanning forward for the next 4F 67 67 53. The container itself says nothing about the codec — that is decided by the first packet on the first page.
Header layout, byte by byte
| Offset | Length | Field | Meaning |
|---|---|---|---|
| 0 | 4 | Capture pattern 'OggS' | 4F 67 67 53. It marks the start of a page, not the start of the file, so a one-second audio clip already contains dozens of them; a hex editor searching for it finds every page boundary in the stream. |
| 4 | 1 | Stream structure version | Always 0. No second version of the Ogg framing has ever been defined, so anything else here means the bytes are not really an Ogg page. |
| 5 | 1 | Header type flag | Bit 0 marks a page whose first packet is continued from the previous page, bit 1 marks the beginning of the logical stream and bit 2 the end of it. The very first page of a file therefore reads 02. |
| 6 | 8 | Granule position | A little-endian signed 64-bit position whose meaning is defined by the codec, not by Ogg — a PCM sample count for Vorbis, a count of 48 kHz samples for Opus. All bits set (-1) means no packet finishes on this page, so there is no new position to report. |
| 14 | 4 | Bitstream serial number | A little-endian random-ish id identifying the logical stream this page belongs to. A file carrying video and audio interleaves pages with different serials, and a chained file has one serial per section. |
| 18 | 4 | Page sequence number | Little-endian, counting from 0 within each logical stream. A jump in this number is exactly how a decoder knows a page was dropped rather than the data being corrupt. |
| 22 | 4 | Page checksum | A CRC-32 over the entire page with this field temporarily zeroed, using polynomial 0x04C11DB7 with no input or output reflection and no final XOR — deliberately not the same CRC-32 that ZIP and gzip use, so the two cannot be confused. |
| 26 | 1 | Number of page segments | How many entries the segment table has, 0 to 255. It caps a page at 27 + 255 + 255 x 255 = 65307 bytes, which is why Ogg latency is bounded no matter what the codec does. |
| 27 | variable | Segment table | One byte per segment, each 0-255. A packet's length is the running sum until a value below 255 terminates it, so a value of exactly 255 always means 'continues'. This is where every hand-written Ogg parser goes wrong. |
| variable | variable | First packet — the codec identification header | Immediately after the segment table, so offset 28 on a first page with one segment. Vorbis writes 01 followed by 'vorbis', Opus writes 'OpusHead', FLAC-in-Ogg writes 7F followed by 'FLAC', and Theora writes 80 followed by 'theora'. This, not the file extension, is what the audio actually is. |
Telling it apart from its neighbours
| Easily confused with | How to tell |
|---|---|
| oga/ogv/opus | There is nothing to distinguish at container level: all four extensions are the same 'OggS' framing, and the convention is only that .oga is audio, .ogv video and .opus an Opus stream. The answer is always the identification packet after the segment table — 01 'vorbis' at offset 28 in a plain Vorbis file, 'OpusHead' at offset 28 in an Opus one. Renaming the file changes nothing, and neither does trusting the MIME type. |
| FLAC | FLAC exists in two skins and they are easy to confuse. Native FLAC starts 66 4C 61 43 at offset 0 and goes straight into a 34-byte STREAMINFO block. FLAC inside Ogg starts 4F 67 67 53 like anything else, and the marker 7F 46 4C 41 43 appears at offset 28, followed by a mapping version, a header-packet count, and only then the native 'fLaC' marker and its STREAMINFO. |
| WebM | The other patent-free open container, and the usual alternative when people ask which one to use. WebM and Matroska are EBML documents beginning 1A 45 DF A3, which shares no bytes at all with 'OggS'. WebM won in browsers for video; Ogg kept Vorbis and Opus. |
| MP3 | MP3 is a bare frame stream with no container, beginning with an 'ID3' tag or a frame sync of eleven set bits. It has no page checksums, no sequence numbers and no way to signal a lost frame, which is precisely the gap Ogg was designed to fill for streaming. |
How these files break
- A dropped page in a live stream. Ogg treats this as normal rather than fatal: the sequence number at offset 18 jumps, the decoder reports a gap, and playback resumes at the next capture pattern. A partially corrupt download recovers the same way, by scanning forward for 4F 67 67 53 and picking up from there.
- Truncation with no end-of-stream page. Because the last page never gets bit 2 of its header type flag set, nothing states the final granule position, so the total duration is unknown. The audio plays to the end of what arrived while the seek bar and the reported length stay wrong.
- Bit rot inside a page body. The page checksum at offset 22 fails and a decoder discards that whole page — a fraction of a second of audio — instead of the file. The damage is audible as a click, and every later page still verifies.
- Naive concatenation. Joining two Ogg files with `cat` produces a legal chained stream with two different serial numbers, but a great many players stop at the first end-of-stream page and report the length of the first file only. Remuxing rather than concatenating is the fix.
- Prepended bytes. An HTTP error body or an ID3 tag glued on the front pushes the first capture pattern off offset 0. Every page is intact and a resynchronising player still finds them, but a detector that only reads offset 0 reports the file as unknown.
Where the format stands today
Ogg's job today is narrower than it once was but very secure. Vorbis was the free answer to MP3 and is still what a huge number of games and open-source applications ship their audio in, because it was unencumbered when MP3 was not. Opus, standardised in RFC 6716 and carried in Ogg for files and in RTP for calls, is now the default voice codec of WebRTC and the best general-purpose low-latency audio codec there is, so Ogg came out of the codec wars with the winner inside it. For video the container lost decisively to WebM and MP4, and .ogv is effectively historical. What keeps Ogg first choice is streaming that has to survive loss: pages are self-describing, checksummed and resynchronisable, so a decoder can join a live stream mid-flight and recover from a dropped packet without any out-of-band signalling.
Open Ogg 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 Ogg — compare their leading bytes.