01 Overview
NVS (Non-Volatile Storage) is a lightweight key-value store provided by ESP-IDF, backed by a dedicated partition in the module's internal flash. It is designed for small data items such as configuration parameters, calibration data, counters, and device flags.
Unlike RAM, NVS retains data across power cycles, making it the default place to store Wi-Fi credentials, device serial numbers, user settings, and other critical information. Using NVS avoids re-configuring the device on every boot and preserves user data across OTA updates.
Typical use cases include saving provisioning results (e.g., SSID and password), storing sensor calibration offsets, recording device operation counts, and saving user interface preferences. It is not suitable for large files (firmware, logs, images) — use SPIFFS or SD card for those.
NVS supports multiple namespaces, each containing multiple key-value pairs. Key names are limited to 15 characters, and value types include integers, strings, and binary blobs.
NVS includes wear leveling and power-loss safety mechanisms, but frequent writes accelerate flash wear. Therefore, design write frequency carefully, e.g., cache counters or use wear-leveling algorithms.
In ESP-IDF, NVS is the underlying storage for many components (Wi-Fi, Bluetooth), so understanding it is essential for reliable firmware development.