Basics · 9 min read

ESP32 Partition Scheme: Fix Sketch Too Big, Huge APP and OTA

ESP32 partition scheme explained: why Sketch too big appears, real sizes of Huge APP, Minimal SPIFFS and OTA schemes, 4/8/16 MB flash and custom partitions.csv.

The ESP32 partition scheme is the table that decides how the ESP32's flash memory is shared between your program, OTA updates, the file system and settings, and in the Arduino IDE you pick it under Tools > Partition Scheme. The "Sketch too big" error you hit after adding Wi-Fi, Bluetooth and a few libraries is usually about this table, not your code: on an ESP32 with 4 MB of flash, the default scheme gives your program only 1.25 MB, and the rest goes to the OTA spare slot and the file system.

This guide shows why the error appears using real compiler output, then walks through the partitions inside the flash, the real sizes of the Huge APP, Minimal SPIFFS, No OTA and OTA schemes, the right choice for 4, 8 and 16 MB boards, how to make room when you use Wi-Fi and Bluetooth together, and how to write your own partitions.csv. At the end there's a small sketch that makes the board print its own partition table, plus what happens to your files when you switch schemes. If you're new to the board, start with what is the ESP32.

ESP32 development board
Most ESP32 development boards have 4 MB of flash; the partition scheme splits it between the program, OTA and the file system.

Why does the Sketch too big error happen?

Let's look at a real example. We compiled a short ESP32 sketch that uses the Wi-Fi, WebServer, HTTPClient and BluetoothSerial libraries together, for the ESP32 Dev Module with the default scheme (2.0.x core), and the Arduino IDE printed the output below. The sketch itself was only 23 lines; what took up the space were the Wi-Fi and Bluetooth stacks those libraries pull in.

Code
1Sketch uses 1613381 bytes (123%) of program storage space. Maximum is 1310720 bytes.
2Global variables use 59240 bytes (18%) of dynamic memory, leaving 268440 bytes for local variables. Maximum is 327680 bytes.
3Sketch too big
4Error during build: text section exceeds available space in board

The program storage space on the first line isn't the whole flash; it's the size of the app partition in the selected scheme: 1,310,720 bytes, exactly 1.25 MB. The program is 1,613,381 bytes, so it shows 123% and the build stops. The dynamic memory on the second line is RAM; it has nothing to do with the partition scheme and isn't the problem here. In other words, the 4 MB board isn't actually full, the share reserved for the program just isn't big enough. So the fix is usually not shortening your code but choosing a scheme with a bigger share.

How is the ESP32 flash divided?

The bootloader sits at the start of the flash: at 0x1000 on the original ESP32 and at 0x0 on the ESP32-S3 and C3. The 4 KB partition table lives at 0x8000, and the bootloader reads it to know where each partition is. After that come small settings partitions, the app partitions that hold your program, and the file system. In the default 4 MB scheme the table looks like this:

PartitionType / subtypeAddressSizePurpose
nvsdata / nvs0x900020 KBSmall settings such as Preferences and Wi-Fi credentials
otadatadata / ota0xE0008 KBStores which app partition boots
app0app / ota_00x100001.25 MBThe running program
app1app / ota_10x1500001.25 MBNew firmware from OTA is written here
spiffsdata / spiffs0x2900001.375 MBSPIFFS or LittleFS file system
coredumpdata / coredump0x3F000064 KBRecord saved at a crash

The reason the program gets two separate partitions is OTA updates. A new program that arrives over the air isn't written over the running one but into the idle second slot; once writing and verification are done, otadata changes and the ESP32 boots from the new slot on restart. If the update is interrupted, the old program stays intact. The price is that in every OTA scheme the program gets less than half the flash. When you upload over USB, the IDE writes boot_app0.bin to 0xE000 to reset otadata, which is why app0 always runs after a wired upload.

Arduino IDE partition schemes: size table

Before choosing a scheme, make sure Tools > Flash Size matches the real flash size of your board, then pick the scheme under Tools > Partition Scheme. The menu names are rounded; the table below shows the real sizes from the ESP32 core's own CSV files. These schemes are the same on ESP32 Dev Module, ESP32-S3 and C3 boards.

Scheme in the menuFlashApp partitionOTAFile system
Default 4MB with spiffs4 MB1.25 MB (1,310,720 bytes)Yes1.375 MB SPIFFS/LittleFS
Default 4MB with ffat4 MB1.25 MBYes1.375 MB FAT
Minimal SPIFFS4 MB1.875 MB (1,966,080 bytes)Yes128 KB
No OTA (2MB APP/2MB SPIFFS)4 MB2 MB (2,097,152 bytes)No1.875 MB
No OTA (1MB APP/3MB SPIFFS)4 MB1 MBNo2.875 MB
Huge APP4 MB3 MB (3,145,728 bytes)No896 KB
Minimal (1.3MB APP/700KB SPIFFS)2 MB1.25 MBNo640 KB
8M with spiffs8 MB3.19 MB (3,342,336 bytes)Yes1.5 MB
16M Flash (3MB APP/9.9MB FATFS)16 MB3 MBYes9.875 MB FAT
16M Flash (2MB APP/12.5MB FATFS)16 MB2 MBYes11.875 MB FAT
Don't set Flash Size or the scheme larger than your board's real flash. If you upload an 8 MB scheme to a 4 MB board, the partition table runs past the end of the flash: either the board won't boot and keeps restarting with a partition table error on the serial monitor (for example "Failed to verify partition table"), or it boots but the file system and OTA misbehave. Also, although Minimal SPIFFS says "190KB SPIFFS" in the menu, current cores give the file system 128 KB, because 64 KB goes to the coredump partition.

Which scheme should I choose?

SituationRecommended schemeWhy
Program smaller than 1.25 MBDefault 4MB with spiffsOTA plus 1.375 MB of file space
Wi-Fi + Bluetooth, OTA neededMinimal SPIFFS1.875 MB for the program, OTA kept
Very large program, no OTA (ESP32-CAM, LVGL, games)Huge APP3 MB for the program
Web UI, audio or image files, no OTANo OTA (2MB APP/2MB SPIFFS)2 MB program + 1.875 MB files
Board with 8 MB flash8M with spiffs3.19 MB program with OTA
ESP32-S3 with 16 MB flash16M Flash (3MB APP/9.9MB FATFS)OTA + about 9.9 MB of files
None of them fitsYour own partitions.csvYou set the sizes you need

With the same code, the 1,613,381-byte example dropped to 82% with Minimal SPIFFS and 51% with Huge APP, and compiled without errors. Minimal SPIFFS keeps OTA, so it's the first scheme to try for Wi-Fi projects; Huge APP gives the most room if you don't need wireless updates. That's also why the ESP32-CAM camera web server example is built with Huge APP; details are in the ESP32-CAM guide. If you use an ESP32-S3 with 8 or 16 MB of flash, leaving the menu at 4 MB wastes more than half of the board's memory.

Wi-Fi and Bluetooth together: how to make room

The Wi-Fi and Bluetooth stacks are the biggest parts of an ESP32 program. For example, even a self-balancing robot sketch that uses only BluetoothSerial weighs 1,068,625 bytes and fills 81% of the default app partition. Add Wi-Fi, a web server and an HTTPS client on top and the program easily passes 1.25 MB. Besides switching schemes, these steps also save space:

  • Change the scheme first: Minimal SPIFFS if you need OTA, Huge APP if you don't; for most projects that's all it takes.
  • Don't use Classic Bluetooth and BLE at the same time: BluetoothSerial and the BLE library together bring two separate stacks; pick one.
  • Use NimBLE-Arduino for BLE: instead of the built-in BLE library, NimBLE does the same job with roughly half the flash and less RAM. For BLE basics, see ESP32 Bluetooth and BLE.
  • Keep Core Debug Level at None: the higher the debug level in the Tools menu, the more log strings are compiled in and the bigger the program gets.
  • Remove libraries you don't use: big libraries added for a single function (cloud clients, every font of a display library) can take hundreds of KB.
  • Skip HTTPS if you don't need it: the TLS layer that comes with WiFiClientSecure makes the program noticeably bigger; plain HTTP is enough for devices on your local network.
To find out what takes up space, add libraries to the sketch one by one and note the byte count on the "Sketch uses" line after each build. The core version matters too: the same program usually compiles a bit bigger with ESP32 core 3.x than with 2.x, so a project right at the limit can hit Sketch too big after an update.

Writing your own partition table: partitions.csv

If none of the built-in schemes fits exactly, you can write your own table. The file must be named exactly partitions.csv and sit in the same folder as the .ino file; the Arduino IDE finds it at build time and uses it instead of the scheme selected in the menu. The example below is for a 4 MB board and covers a need that falls between two built-in schemes: OTA is kept, the program gets 1.625 MB and 640 KB remain for the file system.

Code
1# Name,   Type, SubType, Offset,   Size,     Flags
2# 4 MB, OTA'lı: 2 x 1,625 MB uygulama + 640 KB dosya sistemi / with OTA: 2 x 1.625 MB app + 640 KB file system
3nvs,      data, nvs,     0x9000,   0x5000,
4otadata,  data, ota,     0xe000,   0x2000,
5app0,     app,  ota_0,   0x10000,  0x1A0000,
6app1,     app,  ota_1,   0x1B0000, 0x1A0000,
7spiffs,   data, spiffs,  0x350000, 0xA0000,
8coredump, data, coredump,0x3F0000, 0x10000,
ColumnMeaningRule
NamePartition name (up to 16 characters)LittleFS and SPIFFS look for a partition named "spiffs" by default, FFat for "ffat"
Typeapp or dataPrograms are app, everything else is data
SubTypefactory, ota_0, ota_1 or nvs, ota, spiffs, fat, coredumpOTA needs at least ota_0, ota_1 and otadata
OffsetStart address of the partition in flashApp partitions start on 0x10000 (64 KB) boundaries, data partitions on 0x1000 (4 KB)
SizePartition size (such as 0x1A0000 or 1664K)The end of the last partition must not exceed the flash size
FlagsUsually left emptyFor special cases such as encryption
The Arduino IDE uses a custom partitions.csv, but it still runs the "Sketch too big" check against the limit of the scheme selected in the menu. We tested this with the 2.0.x core: the table was applied, yet the output kept saying "Maximum is 1310720 bytes". Select a menu scheme whose app partition is at least as big as yours (Minimal SPIFFS for this example), and check yourself that the "Sketch uses" value stays below your own app partition (1,703,936 bytes here).

If you use PlatformIO, just add board_build.partitions = partitions.csv to platformio.ini; for a built-in scheme you can also write a core file name such as huge_app.csv or min_spiffs.csv. When building from the command line with arduino-cli, the scheme is appended to the board name: esp32:esp32:esp32:PartitionScheme=huge_app. If you're thinking about moving to PlatformIO, the PlatformIO setup guide makes it easier.

Ask the ESP32 for its partition table

If you're not sure which scheme is actually on the board, ask the board itself. The sketch below needs no extra libraries; it prints the program size, the running app partition, the OTA target and the name, address and size of every partition in the table to the Serial Monitor.

C++ (Arduino IDE)
1#include <esp_partition.h>
2#include <esp_ota_ops.h>
3
4void listPartitions(esp_partition_type_t type, const char *kind) {
5  esp_partition_iterator_t it = esp_partition_find(type, ESP_PARTITION_SUBTYPE_ANY, NULL);
6  while (it != NULL) {                               // sonda next() iteratörü kendisi bırakır / next() releases it at the end
7    const esp_partition_t *p = esp_partition_get(it);
8    Serial.printf("%-5s %-9s 0x%06X  %5u KB\n", kind, p->label,
9                  (unsigned)p->address, (unsigned)(p->size / 1024));
10    it = esp_partition_next(it);
11  }
12}
13
14void setup() {
15  Serial.begin(115200);
16  delay(1000);
17  // Menüdeki Flash Size ayarı / Flash Size selected in the menu
18  Serial.printf("Flash: %u MB\n", (unsigned)(ESP.getFlashChipSize() / (1024 * 1024)));
19  Serial.printf("Program / sketch: %u KB\n", (unsigned)(ESP.getSketchSize() / 1024));
20
21  const esp_partition_t *running = esp_ota_get_running_partition();
22  const esp_partition_t *next = esp_ota_get_next_update_partition(NULL);
23  Serial.printf("Calisan bolum / running: %s\n", running->label);
24  if (next != NULL && next != running) {
25    Serial.printf("OTA hedefi / OTA target: %s (%u KB)\n", next->label, (unsigned)(next->size / 1024));
26  } else {
27    Serial.println("OTA bolumu yok / no OTA partition");
28  }
29
30  listPartitions(ESP_PARTITION_TYPE_APP, "app");     // uygulama bölümleri / app partitions
31  listPartitions(ESP_PARTITION_TYPE_DATA, "data");   // nvs, otadata, spiffs, coredump
32}
33
34void loop() {
35}

With the default scheme the output shows 1280 KB for app0 and app1, 1408 KB for spiffs and 64 KB for coredump; with Huge APP you'll see a single 3072 KB app0 and the "no OTA partition" line. The Flash line in the sketch reflects the Flash Size you picked in the menu, not the real size of the chip. To get the real size, run esptool with the flash_id command and look at the "Detected flash size" line, or check the code printed on the module: ESP32-WROOM-32E-N4 means 4 MB of flash, N8 means 8 MB and N16 means 16 MB; in a name like ESP32-S3-WROOM-1-N16R8, R8 stands for 8 MB of PSRAM.

What happens to files and settings when you change the scheme?

  • Settings survive: in all built-in schemes the nvs partition sits at the same place (0x9000), so values saved with Preferences and Wi-Fi credentials are still there after a scheme change. The EEPROM library on the ESP32 also uses NVS under the hood.
  • The file system is lost: because the address and size of the SPIFFS or LittleFS partition change, old files can't be read. LittleFS.begin(true) formats the partition; you'll need to upload your files again.
  • OTA can't change the scheme: OTA only writes to an app partition and never touches the partition table. To switch to a new scheme, program the board over USB once.
  • Full clean-up: if you enable Tools > Erase All Flash Before Sketch Upload, the whole flash is erased before uploading; that resets everything, nvs included.

Common errors and fixes

Error or symptomCauseFix
Sketch too big; text section exceeds available space in boardThe program is bigger than the app partition of the selected schemeChoose Minimal SPIFFS or Huge APP, remove unneeded libraries
Keeps restarting after upload, "Failed to verify partition table"An 8 or 16 MB scheme uploaded to a board with 4 MB of flashSet Flash Size and the scheme to match the board's real flash
LittleFS mount failed, files are goneThe file system partition moved when the scheme changedFormat the partition once, upload the files again
OTA update doesn't start or stops halfwayNo second app partition in the scheme, or the new program is bigger than the OTA slotSwitch to an OTA scheme over USB, shrink the program
Sketch too big despite a custom partitions.csvThe IDE takes the limit from the scheme in the menuSelect a menu scheme whose app partition is at least as big as yours
partitions.csv is ignoredWrong file name or locationPut the file next to the .ino, named exactly partitions.csv
For strange boot errors, first open the serial monitor at 115200 baud and reset the ESP32; the bootloader prints partition table errors in the first lines. If the board won't accept uploads at all, the problem isn't the partition scheme but the connection; follow the steps in ESP32 Failed to connect.

Once you understand the partition scheme, "Sketch too big" stops being a wall and you can share the ESP32's flash to suit your project: OTA, a big program or lots of files, you make room for whatever matters most. In the BlueGrays app you'll find ESP32 projects for OTA updates, Wi-Fi connection, web servers and weather displays with wiring diagrams and commented code, step by step, so you can try which scheme they need on your own board.

Frequently asked questions

How do I fix "Sketch too big" on the ESP32?

Pick a scheme with a bigger app partition under Tools > Partition Scheme: Minimal SPIFFS (1.875 MB) if you need OTA, Huge APP (3 MB) if you don't. The error means the program doesn't fit in the selected scheme's 1.25 MB app share, not in the 4 MB flash. If it still doesn't fit, remove unneeded libraries or use a board with 8 MB of flash.

What do I lose with the Huge APP partition scheme?

Huge APP gives the program 3 MB, but with no second app partition you can't do wireless OTA updates. The file system also shrinks from 1.375 MB to 896 KB. If you always update the project over USB, that's not a real loss.

Which ESP32 partition scheme should I use for OTA?

On a 4 MB board, use the default scheme if your program is under 1.25 MB and Minimal SPIFFS if it's bigger; both have two app partitions. On an 8 MB board, 8M with spiffs gives 3.19 MB of program space with OTA. OTA doesn't work with Huge APP or the No OTA schemes.

Does changing the partition scheme erase my files?

Files in SPIFFS or LittleFS become unreadable because the file system partition changes address and size, so you'll need to upload them again. Settings saved with Preferences and Wi-Fi credentials survive, because the nvs partition always stays in the same place. If Erase All Flash is enabled, everything is wiped.

How do I check how much flash my ESP32 has?

Run esptool with the flash_id command; the "Detected flash size" line shows the real size. The code on the module helps too: N4 means 4 MB, N8 means 8 MB and N16 means 16 MB of flash. The vast majority of classic ESP32 dev boards and the ESP32-CAM have 4 MB.

Where do I put a custom partitions.csv in the Arduino IDE?

Put the file, named exactly partitions.csv, in the same folder as your .ino file; the IDE uses it instead of the scheme in the menu when it builds. App partitions must start on 0x10000 boundaries and the total must not exceed the flash. Because the IDE checks the size against the menu scheme, keep a large enough scheme selected there as well.

See all projects
ESP32 OTA Update — Wireless Firmware Installation (With LCD Screen)
ES-30Advanced
Premium

ESP32 OTA Update — Wireless Firmware Installation (With LCD Screen)

In this project you'll learn to upload new firmware to the ESP32 over Wi-Fi, without a USB cable. With the ArduinoOTA library the ESP32 becomes visible on the network and shows up automatically as bluegrays-ota under "Network port" in the Arduino IDE. The first upload goes over USB; after that every update is wireless, a key feature for devices out in the field.

4.6(14)
22
ESP32 Wi-Fi STA Connection (with LCD Screen)
ES-25Advanced

ESP32 Wi-Fi STA Connection (with LCD Screen)

In this project, we connect the ESP32 to the home Wi-Fi network in Station (STA) mode in a secure, fault-tolerant manner. We store the SSID and password in a separate secrets.h file to prevent leaking to Git, set up an auto-reconnect mechanism, and display the RSSI signal level and IP address on an I2C LCD screen. The internal LED works as a status indicator. It is a production-grade connection manager.

4.4(21)
40
ESP32 Asynchronous Web Server (with IP Display on LCD)
ES-27Advanced

ESP32 Asynchronous Web Server (with IP Display on LCD)

In this project, we’re turning the ESP32 into an asynchronous web server that you can control from your phone or computer on the same Wi-Fi network. Thanks to the ESPAsyncWebServer library, the server can process multiple requests simultaneously (unlike the classic WebServer.h, which blocks on a single request). You’ll be able to open the ESP32’s IP address in a browser and click the ON/OFF buttons (the /on and /off routes) to turn the LED connected to GPIO 5 on and off.

4.8(16)
27
ESP32 WebSocket Counter (2 Buttons + LCD + Real-Time Web)
ES-28Advanced
Premium

ESP32 WebSocket Counter (2 Buttons + LCD + Real-Time Web)

In this project, two buttons wired to the ESP32 (GPIO 5 counts up, GPIO 4 counts down) change a counter. The value updates instantly both on a 16x2 I2C LCD and, through the WebSocket support of ESPAsyncWebServer, in every connected browser without reloading the page. Instead of HTTP polling a single persistent connection is used, and the ESP32 sends the new value to everyone with ws.textAll().

4.5(14)
23
ESP32 mDNS: Accessing the Device via bluegrays-esp.local (with LCD Screen)
ES-29Advanced
Premium

ESP32 mDNS: Accessing the Device via bluegrays-esp.local (with LCD Screen)

In this project we add an mDNS (Multicast DNS) service to the ESP32, so you reach it by a readable host name like bluegrays-esp.local instead of an IP address. Even if the IP assigned by DHCP changes, the device always answers to the same name. A small web server on the board lets you control the LED from your browser at http://bluegrays-esp.local/.

4.8(14)
23
ESP32 HTTPClient + Weather API (with LCD Screen)
ES-31Advanced
Premium

ESP32 HTTPClient + Weather API (with LCD Screen)

In this project the ESP32 makes a REST API call over the internet to a weather API (wttr.in) using HTTPClient.h. The JSON response is parsed with ArduinoJson v7, and the city, temperature, humidity, weather and wind are shown on an I2C LCD. wttr.in needs no API key; just type the name of any city.

4.7(13)
20
ESP32 HTTPClient + Weather API (with SSD1306 OLED Display)
ES-32Advanced
Premium

ESP32 HTTPClient + Weather API (with SSD1306 OLED Display)

In this project the ESP32 makes a REST API call over the internet to a weather API (wttr.in) using HTTPClient.h. Unlike the I2C LCD version, it uses an SSD1306 OLED (128×64) display, with large text and vector icons for a richer look. Seven weather icons (sunny, rainy, snowy and more) are drawn on the fly, with no bitmap files.

4.3(10)
22
ESP32 Motion Alarm System (PIR + Buzzer + LED + Telegram)
ES-41Advanced
Premium

ESP32 Motion Alarm System (PIR + Buzzer + LED + Telegram)

A smart security alarm: when the PIR sensor detects motion, it sounds the buzzer, lights the LED and sends the owner an instant Telegram notification. A 30-second cooldown limits how often the alarm repeats; it does not filter out the PIR sensor's false detections. Use it at home, in a garage, a storeroom or a study.

4.0(1)
9