A native FLAC stream is the four-byte marker, one or more metadata blocks, and then audio frames. Everything is big-endian except the lengths inside a Vorbis comment, which are little-endian as Vorbis comments always are. This page follows RFC 9639.
The marker
The stream starts with the four ASCII bytes fLaC
(66 4C 61 43). At least one metadata block follows, and the first must be
STREAMINFO.
Metadata block header
Each metadata block starts with a 4-byte header:
| Bits | Field | Meaning |
|---|---|---|
| 1 | Last block flag | 1 on the last metadata block; the audio frames follow it |
| 7 | Block type | See below |
| 24 | Block length | The bytes that follow this header, without the header itself, big-endian. A block therefore holds at most 16,777,215 bytes, which limits pictures and tags |
Block types
| Value | Block | Holds |
|---|---|---|
| 0 | STREAMINFO | Sample rate, channels, depth, length and the audio’s MD5. Always first, exactly one |
| 1 | PADDING | Spare room for later metadata edits. Any number of blocks |
| 2 | APPLICATION | Data for one application, by registered ID |
| 3 | SEEKTABLE | Places to jump to. At most one |
| 4 | VORBIS_COMMENT | Tags as name=value text. At most one |
| 5 | CUESHEET | Tracks and index points, as on a CD |
| 6 | PICTURE | A picture, such as a cover |
| 7 to 126 | Reserved | Not defined. The length field would let a reader skip such a block; RFC 9639 does not say what a decoder must do with one (skipping it is common practice, not the specification) |
| 127 | Forbidden | Would make the header look like the start of a frame sync code |
The frames
After the block marked as last, the audio starts: a run of frames, in time order, each holding one block of samples. The stream has no index of them and no closing mark: frames run to the end of the file, and the seek table is optional.
Not part of the format
Some taggers put an ID3v2 tag in front of the marker. It is not part of FLAC, but its size is stated in its own header, so a reader can skip it, and many do. Likewise an ID3v1 or APEv2 tag sometimes follows the frames. RFC 9639 does not describe such tags or say what a decoder does with bytes that are not a frame. This viewer’s own practice, not the specification: it recognises ID3v1 and APEv2 tags at the end and reports other bytes that are not a valid frame as unreadable.
The viewer shows every field of these tags (the MP3 viewer’s readers do), with one defined
limit that belongs to ID3v2 and not to FLAC: the contents of an encrypted
ID3v2 frame. The ID3v2.4 structure document (section 4.1.2, flag m) says an
encrypted frame carries one extra byte that names the method, and the encryption method
registration frame (ENCR, ID3v2.4 frames document section 4.25) names the
organisation that is responsible for the method with a URL, a symbol in the range
$80 to $F0 and optional data. The specification defines no
cipher and puts none of the key in the tag, so those bytes can only be shown as bytes,
labelled, with the method byte and its registration beside them.
FLAC audio can also be carried in other containers, in which case this layout does
not apply: the Ogg mapping starts each
stream with the packet 7F 46 4C 41 43 and puts each block and each frame
in a packet of its own; Matroska uses the
codec ID A_FLAC and keeps
the marker and blocks in its CodecPrivate data; MP4 has a separate mapping document.
As a file, FLAC has the media type audio/flac (formerly
audio/x-flac), the extension .flac and the magic number
fLaC.
A stream that starts at a frame
RFC 9639 section 4 says that each frame starts with a byte-aligned 15-bit sync code so
that a decoder can start decoding at any place in the stream (it checks that it synced
correctly by parsing the rest of the frame header and validating the CRC-8), and that
each frame header carries the sample rate, bit depth and channel count so that a decoder
can do so even without a STREAMINFO block. Section 9.1 adds that the properties were
put in each frame header to permit multicasting. A recording of such a stream has no
fLaC marker and no metadata blocks: it starts at a frame header, or with
the bytes of a frame that was cut in two. The viewer shows a file
named .flac that does not start with the marker as audio frames from its
first byte, reports that it has no marker, STREAMINFO or other metadata, and lists
bytes before the first valid frame as unreadable. A file is recognised as FLAC by its
marker only: a stream without one is not recognised by its contents.
Invalid data, resources and interoperability
Invalid data (RFC 9639 section 5). When a file holds data that is forbidden or otherwise not valid, decoder behaviour is left unspecified, and a decoder may stop decoding at it. The RFC’s examples: a decoded sample outside the range of the frame’s bit depth (in 8 bits, anything outside −128 to 127); wasted bits that leave a subframe bit depth of zero or less; a frame header CRC-8 or frame footer CRC-16 that does not validate; a forbidden bit pattern. Section 8.2 adds that incorrect STREAMINFO values leave the behaviour unspecified too, and warns that trusting them without checking can lead to buffer overflows.
Resources (section 11). Decoders must be robust against malformed data, which must not make them overrun memory or use an excessive amount of resources. Output can be far larger than input: a frame of eight constant subframes at block size 65535 and 32 bits is 49 bytes and decodes to more than 2 megabytes; an encoder that picks a Rice parameter that does not fit its residual can write unary codes of more than 4 gigabytes for one sample. Metadata can be extreme too (millions of Vorbis comment fields, very long picture descriptions).
Interoperability (Appendix C, informational). For files that most decoders handle, an encoder should stay in the streamable subset, use a fixed block size with common block sizes (except for the last block), avoid 5-bit Rice parameters for 16 bits or less, avoid escaped Rice partitions, pad uncommon bit depths (such as 12 or 20) to a whole number of bytes with wasted bits, keep to common sample rates and two channels where players must render the audio, and keep one set of audio properties for the whole stream. The FLAC wiki page on interoperability has later advice.