
ESP32 Flash Partition Error: Not Enough Space Fix
To fix an ESP32 flash partition error, open Tools, Partition Scheme in Arduino IDE and pick Huge APP (3MB No OTA/1MB SPIFFS) when you do not need OTA. That gives the app about 3 MB instead of the default app slot. Set Flash Size to match your board, erase the flash when the layout is corrupt, and remove unused libraries.
Quick facts
- Error line: Sketch too big. Sketch uses X bytes (Y%) of program storage space. Maximum is Z bytes.
- Huge APP scheme: about 3 MB for the app, 1 MB for SPIFFS, no OTA slot.
- Default scheme: two app slots for OTA plus a filesystem, so one app slot is much smaller than the flash.
- Flash Size menu: a claim, not a detection. Set it to the real flash on the module.
- Changing the scheme erases stored data. Decide the scheme at the start of a project.
What is a partition table?
The flash chip on an ESP32 board holds more than your sketch. It holds the bootloader, the partition table, the app, the file system, and the settings storage. The partition table is a map that divides the flash into slices. Each slice has a name, a type, a size, and an offset. The app slice holds your compiled sketch. The OTA slices hold update copies. The file system slice holds files for SPIFFS or LittleFS. The NVS slice holds settings such as WiFi credentials. The Arduino IDE picks a partition table from the Partition Scheme menu and writes it when you upload. The default scheme on a 4 MB board gives each app slot about 1.2 MB. The rest goes to the second OTA slot and the file system.
The compiler checks your sketch size against the app partition, not against the whole flash. A sketch that is 2 MB cannot fit in a 1.2 MB app slot, even though the board has 4 MB of flash. That is the most common confusion in this error. The board has room, but the slice for the app does not. The fix is a bigger app slice, a smaller sketch, or a board with more flash. Read the IDE output line after a failed compile. It prints Sketch uses X bytes of program storage space and Maximum is Y bytes. The Maximum value is the app partition size. Compare it to your sketch size before you change anything.
Which partition scheme should you pick?
Pick the scheme at the start of a project and do not change it later. Changing the scheme moves every boundary, so stored files and settings do not survive. The default scheme is Default 4MB with spiffs. It gives two app slots for OTA updates and a file system slice. Use it when the project needs OTA updates or file storage. Pick Huge APP (3MB No OTA/1MB SPIFFS) when the sketch is large and you do not need OTA. It gives the app about 3 MB and the file system 1 MB. It has no second app slot, so OTA updates cannot run. Pick Minimal SPIFFS when the sketch is large and you need only a small file system. Pick No OTA (2MB APP/2MB SPIFFS) when you need a large file system and no OTA.
An S3 board with 16 MB of flash has more room. The N16R8 board in this guide carries 16 MB of flash and 8 MB of PSRAM. Its default scheme still limits the app slice, so a large sketch can fail on a 16 MB board too. Set the Flash Size menu to 16 MB for that board, then pick a scheme that matches the project. A custom partition table is a CSV file named partitions.csv in the sketch folder. The IDE picks it up automatically. A custom table is the right path when no built-in scheme fits, but it is an advanced step. Start with the built-in schemes and move to a custom table only when you need a slice size that no built-in scheme offers.
How do you fix a sketch too big error?
Try the fixes in order. First, pick a bigger app partition. Open Tools, Partition Scheme and select Huge APP (3MB No OTA/1MB SPIFFS). Compile again. The Maximum value in the output should rise to about 3 MB. If the sketch still does not fit, remove unused libraries. Every #include of a large library adds flash, even if you call only one function from it. A WiFi library, a TLS library, a BLE library, and a display driver together can pass 1 MB before your own code exists. Remove the include and the code that uses it, then compile again. Trim long Serial.print strings, because each string takes flash. On ESP32, wrap constant strings in a flash string helper only when the core supports it.
Next, use lighter libraries. A small LCD library instead of a full graphics library can save tens of kilobytes. A minimal JSON parser instead of a full one can save more. Check the library size in the compile output. The IDE prints the sketch size and the global variable use after each build. Watch those numbers as you add libraries, not at the end of the project. If the sketch still does not fit after the scheme and the library trim, move to a board with more flash. An S3 N16R8 board with 16 MB of flash gives a larger app slice than a 4 MB DevKit board. Do not buy a bigger board to hide a bloated sketch. Trim first, then upgrade.
How do you fix a flash size mismatch?
The Flash Size menu is a claim, not a detection. It tells the uploader how much flash the module has. Most ESP32 DevKit and C3 SuperMini boards have 4 MB. The S3 N16R8 board has 16 MB. If the menu says 2 MB on a 4 MB board, esptool will refuse to write past 2 MB. The error reads File firmware.bin will not fit in 2097152 bytes of flash. Set Tools, Flash Size to the real size on the module. The module marking on the metal shield names the flash size. A WROOM-32 module is 4 MB. A WROOM-32E module can be 4 MB or 8 MB. Check the board documentation when the shield marking is unclear.
A merged binary written at the wrong address can also overflow the flash. A merged or factory .bin file already holds the bootloader and the partition table, so it must be written at address 0x0. Writing it at 0x10000 pushes it past the end of the flash. Use esptool with the address from the build output, or use the IDE upload, which sets the addresses for you. If esptool reports an auto-detected flash size that differs from the menu, trust the module marking and the board documentation. The auto-detect reads the chip ID, and a wrong board entry can report the wrong size.
When should you erase the flash?
Erase the flash when the layout is corrupt, when the board loops at the bootloader, or when a partition change leaves old data in the wrong place. The Arduino IDE has an Erase All Flash Before Sketch Upload option in the Tools menu. Turn it on, upload once, then turn it off. It wipes the app, the file system, and the settings. WiFi credentials stored in NVS will be gone. Back up any data you need before you erase. The esptool command is esptool.py –chip esp32 –port PORT erase_flash, with PORT replaced by your port name. Hold BOOT during the command if the board needs manual boot mode.
Do not erase the flash for every failed upload. An erase fixes a corrupt layout, not a bad cable or a wrong board entry. Erase once, upload the sketch, and test. If the board still loops, the fault is in the sketch or the partition scheme, not in the flash contents. A board that boots hello_world after an erase but loops on your sketch has a code fault. A board that loops on hello_world after an erase has a hardware or power fault. The brownout guide in this series covers the power fault. The upload guide covers the connection fault.
How do you read the partition table on the board?
Print the table the board is actually running. The IDE menu shows the scheme you selected, not the scheme on the board. A sketch that reads the partition table settles the argument in seconds. The ESP-IDF API has esp_partition_find, and the Arduino core has ESP.getSketchSize and ESP.getFreeSketchSpace. A short sketch that prints the running partition label, the sketch size, and the free space tells you what the board really holds. Use those 2 calls to print the label, the sketch size, and the free space. Compare the free space to the sketch size before you add a library. That habit catches a full app partition early, when the fix is a scheme change and not a rewrite.
Record the scheme in your project notes. Write the board, the flash size, the partition scheme, and the core version in a README file in the project folder. A teammate or a future you can rebuild the project from those four lines. A project with no notes and a custom partition table is a project that cannot be rebuilt. The PlatformIO guide in this series shows how to pin the platform and the board in platformio.ini. The same habit applies to the partition scheme. Pin it, record it, and do not change it in the field.
Step-by-step: ESP32 flash partition error fix
- Read the IDE output line. Note the sketch size and the Maximum value, which is the app partition size.
- Open Tools, Partition Scheme and select Huge APP (3MB No OTA/1MB SPIFFS) when you do not need OTA updates.
- Compile again and confirm the Maximum value rose to about 3 MB.
- Remove unused libraries and includes, then compile again. Watch the sketch size fall.
- Trim long Serial.print strings and switch to a lighter library when a full graphics or JSON library is too large.
- Open Tools, Flash Size and set it to the real flash on the module: 4 MB for most DevKit boards, 16 MB for an S3 N16R8 board.
- If the layout is corrupt, turn on Erase All Flash Before Sketch Upload, upload once, then turn it off.
- Record the board, flash size, partition scheme, and core version in your project notes.
- If the sketch still does not fit, move to a board with more flash, such as an S3 N16R8 board.
Partition scheme and app space on a 4 MB board
| Partition scheme | App space | OTA updates | File system |
|---|---|---|---|
| Default 4MB with spiffs | About 1.2 MB per app slot | Yes, two app slots | Yes |
| Huge APP (3MB No OTA/1MB SPIFFS) | About 3 MB | No | 1 MB SPIFFS |
| Minimal SPIFFS | Larger app, small file system | Yes | Small |
| No OTA (2MB APP/2MB SPIFFS) | About 2 MB | No | 2 MB SPIFFS |
First code to run
Upload this sketch to read the real numbers on your board. Compare the free sketch space to the size of the sketch you want to upload.
// Partition report sketch for ESP32
// Board: ESP32 Dev Module (DevKit V1)
// Library: none. Uses only the Arduino core.
// This sketch prints the sketch size and the free sketch space.
void setup() {
Serial.begin(115200);
delay(1000);
Serial.print("Sketch size in bytes: ");
Serial.println(ESP.getSketchSize());
Serial.print("Free sketch space in bytes: ");
Serial.println(ESP.getFreeSketchSpace());
Serial.print("Flash chip size in bytes: ");
Serial.println(ESP.getFlashChipSize());
Serial.print("Free heap in bytes: ");
Serial.println(ESP.getFreeHeap());
}
void loop() {
delay(1000); // Nothing to repeat. The report prints once at startup.
}
The flash chip size is the whole chip. The free sketch space is the room left in the app partition. Those two numbers differ, and the app partition is the limit that matters.
Frequently asked questions
What does sketch too big mean on ESP32?
The compiled sketch is larger than the app partition. The IDE prints Sketch uses X bytes and Maximum is Y bytes. The Maximum value is the app partition size, not the whole flash. Pick a larger partition scheme or trim the sketch.
What is the Huge APP partition scheme?
Huge APP (3MB No OTA/1MB SPIFFS) gives the app about 3 MB and the file system 1 MB on a 4 MB board. It has no second app slot, so OTA updates cannot run. Use it when the sketch is large and you do not need OTA.
Does changing the partition scheme erase my files?
Yes. Changing the scheme moves every boundary, so stored files and settings do not survive. Pick the scheme at the start of a project and record it in your project notes.
Why does esptool say the file will not fit in 2097152 bytes?
The flash size setting is 2 MB, but the file is larger. Set Tools, Flash Size to the real flash on the module. Most DevKit boards have 4 MB. An S3 N16R8 board has 16 MB.
How do I erase the flash on ESP32?
In Arduino IDE, turn on Erase All Flash Before Sketch Upload in the Tools menu, upload once, then turn it off. Or run esptool.py –chip esp32 –port PORT erase_flash from a terminal. Erasing wipes WiFi credentials and stored files.
Parts used in this guide
This guide fixes flash errors on the ESP32 DevKit V1 board and the S3 DevKitC-1 board linked below. Set the Flash Size menu to the real flash on your module.
- ESP32 DevKit V1 Development Board, 30-Pin WROOM-32, WiFi + Bluetooth, Dual-Core
- ESP32-S3 Development Board DevKitC-1 N8R2 N16R8
Related guides
- ESP32 vs ESP32-S3 vs ESP32-C3 vs ESP32-C6: Which Chip for Your Project
- ESP32 Brownout Reset and Boot Loop: Causes and Fixes
- ESP32 Upload Failed: Timed Out Waiting for Packet Header
Sources
- Partition tables and flash size
- Fix Sketch too big error
- Fix file will not fit in flash error
- Partition schemes in Arduino IDE
Last updated: 2026-11-21
