APE tags come from Monkey’s Audio and appear on MP3 files too, usually written by MP3Gain and other tools. They are lists of named items at the end of the file, placed before any ID3v1 tag. Numbers are little-endian. APEv1 has only a footer, APEv2 may also have a header.
Layout
| Part | Size | Notes |
|---|---|---|
| Header | 32 | optional; APEv2 only |
| Items | varies | in the order written; the specification strongly recommends sorting by size, smallest first |
| Footer | 32 | always in APEv1; usual in APEv2 |
Header and footer
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 8 | Preamble | APETAGEX |
| 8 | 4 | Version | 1000 for APEv1, 2000 for APEv2 |
| 12 | 4 | Tag size | bytes of the items and the footer, not the header |
| 16 | 4 | Item count | items in the tag |
| 20 | 4 | Flags | see below |
| 24 | 8 | Reserved | zero |
| Flag bit | Meaning |
|---|---|
| 31 | the tag has a header |
| 30 | the tag has no footer (read both ways, see the note below) |
| 29 | this 32-byte block is the header (0 for the footer) |
| 3–28 | undefined, must be zero |
| 1–2 | item type, in items (see below) |
| 0 | read-only, in items |
Bit 30 is read two ways. The original specification, Frank Klemm’s page apetagflags.html
(Internet Archive copy of 12 December 2006), says “0: Tag contains a footer, 1: Tag contains no footer”;
the Hydrogenaudio copy said the same from 26 April 2005 to 2006, and an anonymous edit of 14 November 2017
(“fixed the swapping of yes / no”) reversed it. FFmpeg, mutagen and TagLib
take the first reading, the Monkey’s Audio SDK and lofty-rs the second. Find the footer by its
APETAGEX preamble at the end of the file, before any ID3v1 tag, and do not rely on this bit
(details on the Monkey’s Audio page). APEv1 does not use the
flags: they are zero when written and ignored when read.
Items
| Size | Field | Meaning |
|---|---|---|
| 4 | Value size | bytes of the value |
| 4 | Item flags | bit 0 read-only; bits 1–2 the type: 0 UTF-8 text, 1 binary, 2 external locator (UTF-8: a URL or a file name), 3 reserved |
| varies | Key | 2 to 255 characters from 0x20 to 0x7E, ending in a zero byte |
| value size | Value | text may list several values separated by zero bytes; a binary value, by convention, begins with a file name or description and a zero byte (cover art is stored so) |
Item flag bits 3 to 28 are reserved and should be 0. The keys ID3,
TAG, OggS and MP+ are not allowed, so that a tag
cannot be mistaken for another format. Keys are case sensitive, but two keys in one tag must not differ
only in case, each key occurs once, and readers are recommended to compare without regard to case. A tag
with a header may also stand at the start of a file, before the audio. The explorer
finds tags in both places, names the keys below in any case, and reports forbidden keys,
reserved bits and type 3.
The keys the specification defines (and two families written by gain tools), which readers match without regard to case:
| Key | Meaning | Key | Meaning |
|---|---|---|---|
Title | Title | Subtitle | Subtitle |
Artist | Artist | Album | Album |
Debut album | Debut album | Publisher | Publisher |
Conductor | Conductor | Track | Track number |
Composer | Composer | Comment | Comment |
Copyright | Copyright | Publicationright | Publication right |
File | The source file | Year | Year |
Record Date | Recording date | Record Location | Recording location |
Genre | Genre | Media | Media |
EAN/UPC, ISBN, ISRC | Barcodes and identifiers | Catalog | Catalogue number |
LC | Label code | Language | Language |
Index | Indexes for quick access | Related | Related information |
Abstract | Abstract | Bibliography | Bibliography |
Introplay | Characteristic part of the piece | REPLAYGAIN_*, MP3GAIN_* | Written by gain tools |
Dummy | Placeholder |
Source: the APEv2 specification of the Hydrogenaudio Knowledgebase (the pages on the layout, header, item, flags, key and item value; wiki.hydrogenaud.io answers 403 to direct requests, so they were read from the Internet Archive’s 2024 copies, with the flags page also of 2010, 2015 and 2020; the flags page’s six wiki revisions of 2005 to 2017 and Frank Klemm’s original page were read later, from wiki.hydrogenaudio.org and the Internet Archive), compared by scripts/ape/spec-check-apetag.mjs: the header and footer fields, the flag bits, the item layout, the key rules and the 30 defined keys. The sources of FFmpeg, mutagen, TagLib, lofty-rs, WavPack and the Monkey’s Audio SDK settle what programs do with bit 30. The REPLAYGAIN_* and MP3GAIN_* keys are not in the specification.