Full name: Non-Volatile Storage record.
Definition
An NVS record is one stored item of NVS (Non-Volatile Storage), the storage library of the Zephyr RTOS §6.33 (real-time operating system), which keeps small values in flash memory §6.6 under 16-bit numeric IDs. A record pairs a data part, the value’s bytes, with an 8-byte metadata entry called an ATE (allocation table entry). The ATE holds the ID, the data’s position and length, and a CRC-8 (8-bit cyclic redundancy check §4.32), an error-detecting code over the ATE alone. The newest valid record of an ID holds its current value.
The idea
NVS saves each change as a new record in a circular log §8.14, a flash area of sectors that are filled in turn and reused in a cycle. After a power failure it must decide, for every record, whether the record is complete, which bytes belong to it, and whether its data is intact. The ATE answers the first two, like a library catalog card written only after the book is shelved. NVS writes the data first and the ATE last, so data without an ATE is ignored and the previous record of the ID stays current. The picture stops at the book: a correct card says nothing about whether the pages are intact, and only an optional 32-bit CRC over the data checks it.
How it works
This account follows Zephyr’s documentation and source code as of late 2026; older releases differ. NVS splits its flash area into at least 2 sectors. A sector’s size is a power of 2 and a multiple of the size of an erase block, the smallest region the flash can erase. One sector is always kept erased, so that live records, those still holding current values, can be copied into it during garbage collection §8.16. In each sector, data parts grow upwards from the start and ATEs grow downwards from the end. Both are padded to a multiple of the write block size, the smallest unit the flash programs, for example 4 bytes.
An ATE holds id (16 bits); offset, the start of the data within the sector (16 bits); len, the length of the data part including the data CRC if enabled (16 bits); an unused byte; and crc8, a CRC-8 over the 7 bytes before it. Special ATEs close a full sector, mark a finished garbage collection, or, with length 0, delete an ID.
A write runs as follows.
If the newest record of the ID already holds the new value, stop.
If the option
CONFIG_NVS_DATA_CRCis on, place a CRC-32 (32-bit CRC) of the value directly after it.If the data part and one ATE do not fit into the current sector, close the sector, move on, and collect the oldest sector: copy its live records, write a garbage-collection-done ATE and erase it.
Write the data part.
Write the ATE.
At start-up NVS ignores any ATE whose CRC-8 fails or whose offset and length fall outside the sector’s data area, and any data that no valid ATE points to; it checks no data CRC. A read finds the newest valid ATE of the ID. If the data CRC option is on and the caller’s buffer holds the whole value, NVS recomputes the CRC-32 and returns an error on a mismatch. A partial read, which asks for fewer bytes, is not checked, because the stored CRC-32 covers the whole value and sits after its end.
Worked example
Take flash with a 4-byte write block, as in the nRF52840 §6.4 microcontroller §6.1, 4096-byte sectors and the data CRC on, and store a 10-byte value under ID 0x0010. The data part is bytes, which the ATE’s length field records, padded to 16. With the 8-byte ATE the record takes bytes. If power fails after the data but before the ATE, NVS ignores the data and reads return the old value. If it fails during the ATE, the CRC-8 fails, except in about one case in for random-looking damage. If one bit of the stored value later flips, the ATE still passes; a 10-byte read returns an error, but a 4-byte read returns its bytes unchecked.
One record must fit in a sector. The Zephyr source accepts a value only if its data part, the value plus its 4-byte CRC, is at most the sector size minus 4 ATEs: the record’s own, the close ATE, the garbage-collection-done ATE and one kept free for a deletion. Here that is bytes, so one value holds at most bytes. A 10,000-byte table must be split under several IDs, for example bytes, which occupy bytes. The source counts the room of sectors as bytes, leaving out the spare sector and two reserved ATE slots per sector. That is 8160 bytes for 3 sectors, too little for the table, and 12,240 bytes for 4.
Stated precisely
Let be the write block size, the ATE size (8 rounded up to a multiple of ), the sector size and the value size, all in bytes. Let with the data CRC and without it, and let be rounded up to a whole number.
A record occupies bytes and is accepted only if .
The CRC-8 covers the first 7 bytes of the ATE and nothing else.
The CRC-32 covers the value bytes and is checked only by a read whose buffer holds at least bytes.
After a restart a record counts only if its ATE passes the CRC-8 and its offset and length lie inside the data area. The value of an ID is that of its newest such record, unless that record is a deletion.
Writing data before the ATE is safe if the flash driver finishes the data before it starts the ATE, and if a power failure changes no bytes outside the region being written.
Limits and common mistakes
Neither CRC stops an attacker, who can replace a value and recompute both codes. A value whose origin matters needs a message authentication code §5.7 or a digital signature §5.14. Restoring an old copy of the flash area makes NVS return old values as current.
A valid ATE shows that the record was completely written, not that its data is intact. Without the data CRC, damage to data is never detected. With it, only full reads check, and garbage collection copies data and stored CRC-32 without checking them. Enabling the option on an area written without it invalidates all existing data, as the documentation warns.
One record is all or nothing; a group of records is not. A value split across IDs, or settings that must change together, can be left half old and half new, so such groups need a commit record §8.21 or another transaction §8.7 scheme.
Deleting an ID writes a deletion ATE, and the old bytes stay readable until garbage collection erases their sector; deletion is therefore not zeroization §5.37, the immediate destruction of a secret. All sizes above depend on the NVS release and the flash driver’s write block size.
Questions answered
Which checksum protects metadata, and when is data CRC checked?
The metadata of an NVS (Non-Volatile Storage) record, its 8-byte ATE (allocation table entry), is protected by a CRC-8, an 8-bit cyclic redundancy check computed over the first 7 bytes of the ATE: the ID, the data offset, the data length and an unused byte. It covers the ATE only, and the Zephyr documentation says that it only ensures that the write was completed. The data has a separate CRC-32, a 32-bit cyclic redundancy check stored directly after the value, which exists only when the option CONFIG_NVS_DATA_CRC is on.
The data CRC is checked only when a read asks for the whole value, and a mismatch makes the read return an error. A partial read is not checked, because the CRC-32 covers the whole value and sits after its end, and start-up checks no data CRC. Both checks detect accidental damage, not deliberate replacement.
Related entries: Append-only log (§8.13), Torn write (§8.19), Checksum versus CRC (§4.32), Circular log (§8.14), Garbage collection (§8.16). Further reading: [12, 56].