ESP32 Memory Explained: Flash, NVS, Partitions, PSRAM and SD

Where does your ESP32 keep things? A visual guide to SRAM, PSRAM, flash and the SD card, the partition table, how NVS stores settings, flash write cycles, and how to choose between NVS, LittleFS and the SD card, using the Cardputer ADV as the example.

Oct 1, 2026 8 min read By Atomic Creations

A glowing 8 MB flash memory map split into bootloader, NVS, two app slots and a file system, under the headline Where your bytes live.

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.

  1. The big picture: four kinds of memory
  2. Flash and the partition table
  3. NVS: where settings live
  4. Flash write cycles and wear
  5. NVS vs LittleFS vs SD card
  6. What we learned building GLIDE
  7. 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.

On-chip SRAM 512 KB Variables, stack, buffers FASTEST · WIPED AT POWER-OFF PSRAM none on the ADV Extra RAM on some chips (R in the name) FAST · WIPED AT POWER-OFF Flash 8 MB Your program, NVS settings, small files KEEPS DATA · 100,000 ERASE CYCLES microSD card GBs Bulk files: patches, samples, logs, images KEEPS DATA · REMOVABLE · SLOWEST faster and smaller at the top · bigger and slower at the bottom
The memory ladder on a Cardputer ADV (ESP32-S3FN8). Sizes from Espressif's ESP32-S3 datasheet and M5Stack's specs.
  • 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:

0x000000 0x340000 0x670000 0x7F0000 FIRST 64 KB, ZOOMED IN bootloader0x0 partition table0x8000 nvs · 20 KB0x9000 otadata · 8 KB0xE000 app0 · 3.2 MB the program that runs app1 · 3.2 MB the next version (OTA) spiffs · 1.5 MB LittleFS or SPIFFS files coredump · 64 KB 8 MB total
Arduino-ESP32's 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:

1. Save vol = 7 2. Change it to 8 3. Page full? Move on vol=7 written to the first free slot vol=7 vol=8 new entry appended, old one marked erased usedusedused vol=9 old pagefresh page the full page is erased later, in one go
Simplified: a real NVS page is 4 KB and holds 126 entries of 32 bytes. Because new values are appended, a sector gets erased far less often than your values change. That is NVS's built-in wear leveling.

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?

What are you saving? Only needed while running? Buffers, the current screen, live audio RAM Small settings? Volume, theme, Wi-Fi name, counters NVS Files your app owns? Configs, assets, small logs LittleFS Big, growing or shared? Patches, samples, recordings, PC files SD card
A rule of thumb: the smaller and more frequently read, the higher up it goes.
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 .gpat file 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.
The GLIDE pocket synth

GLIDE

Pocket synth · Cardputer ADV

Full 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.

One email, no newsletter, unsubscribe any time.

Useful? Pass it on

Reddit X
← Browse all guides

Try it in your browser

This is GLIDE. Press anything.

A sketch of the Cardputer synth running right here. The four rows are tuned like strings: hold one key and tap another on the same row and the note slides. Tap a chord on the bottom row, then play over it.

A MINOR PENT ·clashes 0

Press any key. Then try Start a beat.

Keyboard works too: 1 to 0, q to p, a to ; are the strings, z to / is the jam row. Same letters as the real thing.

Scale lock is on, so every key fits. Flip it off to hear a regular keyboard. On the device you also get ten sounds, a looper, tilt control, the speaker and a headphone jack.

Small batches, tested one by one

Get GLIDE ready to play. Tested one by one.

Set up, tested and charged one by one, with a sound library loaded. Switch it on and play, and tap Randomize for a sound nobody else has.

  • HardwareM5Stack Cardputer ADV
  • Keys56, four string rows
  • Auto KeyHears key, mode and tempo
  • OutputSpeaker + 3.5 mm headphone
  • PowerUSB-C, 7 to 10 h a charge
  • UpdatesFree, forever
GLIDE pocket synth with a white face and green trim, on a glossy black surface lit with green lines
Actual size: 84 × 54 mm, about a credit card

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.

One email, no newsletter, unsubscribe any time.

Questions first? Ask the maker on Discord →