Every ESP32 project hits the same wall sooner or later: a setting that will not stick after a reboot, a sketch that suddenly does not fit, or a "where do I even save this?" moment. The answer is almost always about memory. This guide maps it out with pictures, using the ESP32-S3 inside the M5Stack Cardputer ADV as the running example.
The short answer
An ESP32 has SRAM for working memory (fast, wiped at power-off), flash for your program and anything that must survive a reboot, and often a microSD card for big files. Some chips add PSRAM as extra RAM; the Cardputer ADV does not. Flash is split up by a partition table, and small settings live in the NVS partition, which you use from Arduino through the Preferences library.
- The big picture: four kinds of memory
- Flash and the partition table
- NVS: where settings live
- Flash write cycles and wear
- NVS vs LittleFS vs SD card
- What we learned building GLIDE
- FAQ
The big picture: four kinds of memory
Think of it as a ladder. The higher up, the faster and smaller. The lower down, the bigger and slower, and the more it remembers when the power goes out.
- SRAM is where your running code keeps its variables. The ESP32-S3 has 512 KB on the chip, plus 16 KB of RTC memory that can hold values through deep sleep. It is wiped when the power goes.
- PSRAM is extra RAM wired next to the chip. Variants with an R in the name (like the ESP32-S3R8) have it. The Cardputer ADV uses the ESP32-S3FN8: 8 MB of flash inside the chip package and no PSRAM, so big buffers have to fit in SRAM.
- Flash holds your compiled program and keeps everything when the power is off. The chip reads code from it through a cache, so it runs nearly as fast as internal memory.
- The microSD card is a removable FAT drive. Slow next to the rest, but huge, and you can pull it out and read it on a computer. Our Cardputer SD card guide covers formats and sizes.
Flash and the partition table
Flash is not one big blob. A small partition table splits it into named regions, like a hard drive. It sits at address 0x8000, fills one 4 KB sector, and can list up to 95 partitions. Here is the default 8 MB layout Arduino-ESP32 uses, drawn to scale:
default_8MB.csv, to scale. NVS, the place your settings live, is a sliver: 20 KB out of 8 MB.Each region has a job:
| Partition | What it holds |
|---|---|
| bootloader | The first code that runs. Reads the partition table and starts your app. |
| nvs | Small key-value settings that survive reboots (more below). |
| otadata | Which app slot to boot after an over-the-air update. |
| app0 / app1 | Your program. Two slots so an update can be written to one while the other runs. App slots must start on a 64 KB boundary. |
| spiffs | A file system on flash. Despite the name, Arduino projects usually format it as LittleFS today. |
| coredump | A crash snapshot you can read back for debugging. |
Partition table CSV example
The table is a CSV. These are the entries behind the diagram (spacing trimmed to fit a phone):
# Name, Type,SubType, Offset, Size
nvs, data,nvs, 0x9000, 0x5000
otadata, data,ota, 0xe000, 0x2000
app0, app, ota_0, 0x10000, 0x330000
app1, app, ota_1, 0x340000,0x330000
spiffs, data,spiffs, 0x670000,0x180000
coredump,data,coredump,0x7F0000,0x10000
To use your own, pick a Partition Scheme in the Arduino IDE's Tools menu, add board_build.partitions = partitions.csv to platformio.ini in PlatformIO, or choose a custom table in ESP-IDF's menuconfig. Espressif's partition table guide lists every type and rule.
Running several firmwares? On a Cardputer, Launcher installs apps into the app space while they all share one NVS partition. Every app on the device shares that one small space.
NVS: where settings live
NVS (non-volatile storage) is a tiny key-value database in flash. You save a value under a name, inside a namespace, and read it back after any reboot. It handles integers, floats, strings and binary blobs.
The clever part is how it writes. Flash can only be erased a whole 4 KB sector at a time, so NVS never edits in place. It appends:
The limits worth knowing, from Espressif's NVS documentation:
| Limit | Value |
|---|---|
| Key and namespace names | 15 characters max |
| One string | 4,000 bytes max, including the terminator |
| Page size | 4 KB, 126 entries of 32 bytes |
| Default NVS size | 20 KB (Arduino 8 MB table), 24 KB or 16 KB in ESP-IDF's built-in tables |
| Best for | Many small values, not a few large ones |
NVS in Arduino: the Preferences library
In Arduino you rarely touch NVS directly. The Preferences library wraps it, and it is the ESP32 replacement for the old EEPROM library. A boot counter in a few lines:
#include <Preferences.h>
Preferences prefs;
void setup() {
Serial.begin(115200);
prefs.begin("myapp", false); // read-write
int boots = prefs.getInt("boots", 0) + 1;
prefs.putInt("boots", boots);
prefs.end();
Serial.printf("Boot #%d\n", boots);
}
void loop() {}
Flash write cycles and wear
Flash wears out. Espressif's ESP32-S3 datasheet rates its flash at 100,000 program/erase cycles with 20 years of data retention. That sounds like plenty, and for settings it is, as long as you do not write in a loop.
Safe habits
- Save when a value actually changes
- Wait until the user stops turning a knob, then save once
- Save on exit, sleep or a menu close
- Keep fast-changing state in RAM
Wears flash fast
- Saving inside
loop()every pass - Logging sensor data to NVS every second
- Rewriting a big blob for a one-byte change
- Using NVS as a log (use a file or SD)
NVS vs LittleFS vs SD card
The question every project asks: where should this data live?
| NVS | LittleFS | SD card | |
|---|---|---|---|
| Shape | Key-value pairs | Files and folders | Files and folders (FAT) |
| Typical size | 16 to 24 KB | About 1.5 MB | Gigabytes |
| Wear leveling | Built in | Built in | Up to the card |
| Power loss | Resilient | Resilient | Weaker: FAT can break mid-write |
| Read on a PC | No | No | Yes |
Espressif's file system guide backs this up, and adds one warning: SPIFFS is no longer developed, so choose LittleFS for new projects.
What we learned building GLIDE
We hit every question in this guide while building GLIDE, the pocket synth we build on the Cardputer ADV. The hard part was making sure a sound or a setting is never lost.
- NVS is small. At 20 KB it fills up faster than you would think, and once it is full the next save fails.
- So GLIDE keeps its footprint tiny. Only settings and the live working sound live in NVS, and GLIDE mirrors them to the SD card. If the space ever fills up, GLIDE cleans it up on the next boot and restores everything from the card. The screen just says STORAGE FIXED and you keep playing.
-
Big things go on the card. Every saved sound is a small
.gpatfile on the microSD card, in the same format whether it is a slot, a library patch or a Discord attachment. That is why sounds survive firmware updates and travel from card to card. - No card, no problem. The instrument plays exactly the same without one. Only Save to SD needs a card; the ten slots save to the device itself.

GLIDE
Pocket synth · Cardputer ADVFull disclosure: this one is ours. GLIDE turns a Cardputer ADV into a pocket synth: notes slide into each other, scale lock means no wrong notes, and every unit rolls sounds no other device has. All the storage work above is why your sounds and settings survive every update.
Every GLIDE is set up and tested one by one, with a microSD sound library loaded, so it plays the moment you switch it on. Get GLIDE ready to play.
New to the platform? Our ESP32 vs Raspberry Pi guide explains why a microcontroller is a different world from a Linux board.
FAQ
How big is NVS on an ESP32?
It depends on the partition table. Arduino-ESP32's default 8 MB table gives NVS 20 KB, and ESP-IDF's built-in tables use 24 KB or 16 KB. Each 4 KB page holds 126 entries, and a single string can be up to 4,000 bytes.
How many write cycles can ESP32 flash handle?
Espressif's ESP32-S3 datasheet rates the flash at 100,000 program/erase cycles with 20 years of data retention. NVS and LittleFS spread writes out to reduce wear, but you should still avoid saving in a tight loop.
What is the ESP32 partition table?
It is a small table, written as a CSV, that splits the flash into named regions such as nvs, otadata, the app slots and a file system. It is stored at address 0x8000 by default, fills one 4 KB sector and can list up to 95 partitions.
Should I use NVS or LittleFS (SPIFFS)?
Use NVS for small key-value settings like numbers and short strings. Use LittleFS for files your app reads or writes. SPIFFS is no longer developed, so Espressif suggests weighing the alternatives, and LittleFS is the usual choice for new projects.
Does the Cardputer ADV have PSRAM?
No. The Cardputer ADV uses the ESP32-S3FN8, which has 8 MB of flash inside the chip package and no PSRAM. It has the ESP32-S3's 512 KB of on-chip SRAM for working memory.
Does uploading a new sketch erase NVS?
Usually not. Uploading writes the app partition, and NVS lives in its own partition, so saved settings survive. A full flash erase or a new partition table that moves NVS will wipe it.
Next batch · Batch 4
Join the GLIDE waitlist
Batch 4 opens next week. The list gets the email 24 hours before it goes public. One message, nothing more.
Useful? Pass it on
← Browse all guides


