A GNU tar archive has no index and no count of members, so its end is marked in the stream itself: two blocks of zeros where the next header would be. Everything in the archive is a whole number of 512-byte blocks, and GNU tar also fills the last record.
Padding file data
A member’s data starts in the block after its header, or after its sparse extension
blocks, and fills as many blocks as it needs. The last block is padded with zeros, so a
member of n bytes takes n rounded up to the next multiple of 512.
The same holds for the data of L, K and D
entries. A reader finds the next header by rounding up the size: the next
header is at the header’s offset + 512 + ((n + 511) & ~511), plus 512
for each extension block.
The two zero blocks
After the last member come two blocks of 512 zero bytes. A reader stops at the first block that is all zeros, since a real header never is: its checksum would fail. GNU tar warns about “a lone zero block” when the first zero block is not followed by a second. The explorer reports the same, and an archive that ends after a single zero block.
Records and the blocking factor
Tape drives work best with large writes, so tar writes its blocks in groups called
records. The number of blocks in a record is the blocking factor, set with GNU tar’s
-b option. The default is 20, giving records of 10,240 bytes; tar(5)
notes that this is “still the default for most implementations”. GNU tar fills the
last record with zeros after the two end blocks, so an archive it writes with the
default blocking factor is a multiple of 10,240 bytes: a one-file archive whose
blocks come to 2,048 bytes is 10,240 bytes long. The padded GNU archives examined for this
site all follow this.
The explorer shows zeros after the end blocks as record padding, and says when the file is a whole number of 10,240-byte records.
Appending and joining
To add members to an archive (--append), GNU tar overwrites the two zero
blocks with the new headers and writes new zero blocks after them. Joining two archives
with a plain file copy leaves the first archive’s zero blocks and padding in the
middle, so most readers stop there. GNU tar’s --ignore-zeros option reads
past them to the members beyond. The explorer shows a tar header found after the end
of the archive as a further archive.
In a multi-volume archive, a file that runs past the end of one volume continues on
the next in an M
header.
A compressed tar file such as .tar.gz compresses the whole stream,
padding and end blocks included. Runs of zeros compress to almost nothing, so the
padding costs very little.