Skip to content
FR
  1. LuzineDebug
  2. Electronics & Arduino
  3. Sketch too big; see https://support.arduino.cc/h…
Electronics & Arduino Intermediate ≈ 20 min to fix

Fix "Sketch too big" on Arduino and ESP32 (flash memory full)

Error message
Sketch too big; see https://support.arduino.cc/hc/en-us/articles/360013825179 for tips on reducing it.
  • Sketch uses 34560 bytes (107%) of program storage space. Maximum is 32256 bytes.
  • text section exceeds available space in board
  • Not enough memory; see https://support.arduino.cc/hc/en-us/articles/360013825179 for tips on reducing your footprint.
  • Global variables use 2150 bytes (104%) of dynamic memory, leaving -102 bytes for local variables. Maximum is 2048 bytes.
  • Sketch uses 1442345 bytes (110%) of program storage space. Maximum is 1310720 bytes.
In short

The compiled program does not fit in the board's available flash memory, so the IDE refuses to upload it. Remove debug code and heavy libraries, swap the biggest parts for lighter ones, and on ESP32 pick a partition scheme with a larger app partition.

Be the first to confirm this fix

What this error means

After compiling, the IDE compares the binary size ("program storage space", the flash) with the maximum defined for the board. On an Uno, that is 32,256 bytes: 32 KB minus the bootloader. On an ESP32, the limit is not the chip size but the app partition size, 1,310,720 bytes (1.25 MB) with the default 4 MB scheme. The "Not enough memory" variant is about RAM ("dynamic memory"): global variables and strings copied to RAM. Both show up in the "Sketch uses" and "Global variables use" lines.

Common causes

  1. Heavy libraries: display libraries with fonts (Adafruit_GFX, U8g2 in graphics mode), String, printf with float, Wi-Fi and Bluetooth stacks on ESP32.
  2. Lots of text and constant data: Serial.print debug messages, HTML pages, images, lookup tables.
  3. App partition too small on ESP32: the default scheme reserves space for OTA and the file system, and the app is limited to 1.25 MB even on a 4 MB chip.
  4. RAM full ("Not enough memory" variant): large global arrays and string literals that the AVR copies to RAM at startup.
  5. Wrong board selected: a Nano "ATmega328P (Old Bootloader)" only offers 30,720 bytes, an ATmega168 only 14,336.

Step-by-step fix

  1. Read both size lines

    Check which one goes over 100%: "program storage space" (flash, the real "Sketch too big") or "dynamic memory" (RAM, "Not enough memory"). The fixes are not the same.

    plaintext
    Sketch uses 34560 bytes (107%) of program storage space. Maximum is 32256 bytes.
    Global variables use 1520 bytes (74%) of dynamic memory, leaving 528 bytes for local variables. Maximum is 2048 bytes.
    Sketch too big; see https://support.arduino.cc/hc/en-us/articles/360013825179 for tips on reducing it.
  2. Find what takes up space

    List the biggest symbols in the .elf file (in the build folder, path shown with verbose compile output). With ESP-IDF, idf.py size-components gives the size per component.

    bash
    # AVR (Uno, Nano, Mega)
    avr-nm -C -S --size-sort -r build/MySketch.ino.elf | head -n 20
    # ESP32
    xtensa-esp32-elf-nm -C -S --size-sort -r build/MySketch.ino.elf | head -n 20
    # ESP-IDF
    idf.py size-components
  3. Remove debug and heavy code

    Wrap debug messages in a macro so they are removed at compile time. Avoid String and float formatting on AVR, and prefer lighter libraries (for example U8x8 instead of U8g2 graphics mode for plain text).

    cpp
    #define DEBUG 0
    
    #if DEBUG
      #define DBG(x) Serial.println(x)
    #else
      #define DBG(x)
    #endif
    
    void setup() {
      DBG(F("starting"));  // removed entirely when DEBUG is 0
    }
    
    void loop() {}
  4. If it is RAM: F() and PROGMEM

    On AVR, every string literal is copied to RAM at startup. F() keeps Serial.print texts in flash, and PROGMEM does the same for constant arrays, read with pgm_read_byte(). Note: this frees RAM but does not shrink the flash size. On ESP32, const data already stays in flash.

    cpp
    #include <avr/pgmspace.h>
    
    const uint8_t sineTable[] PROGMEM = {128, 153, 177, 199, 218, 234, 245, 253, 255};
    
    void setup() {
      Serial.begin(9600);
      Serial.println(F("This text stays in flash"));
      uint8_t v = pgm_read_byte(&sineTable[3]);
      Serial.println(v);
    }
    
    void loop() {}
  5. ESP32: change the partition scheme

    In the Arduino IDE, Tools > Partition Scheme > "Huge APP (3MB No OTA/1MB SPIFFS)" or "Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS)". Note: "Huge APP" removes OTA updates, and changing partitions wipes the file system content (SPIFFS or LittleFS) on the next flash. Back up your files first.

    bash
    # Arduino CLI
    arduino-cli compile --fqbn esp32:esp32:esp32:PartitionScheme=huge_app MySketch
    
    # PlatformIO (platformio.ini)
    # board_build.partitions = huge_app.csv
    
    # ESP-IDF: Partition Table > "Single factory app (large), no OTA"
    idf.py menuconfig
  6. Move to a bigger board

    If the project really needs all that code, switch boards: a Mega 2560 offers 253,952 bytes of flash and 8 KB of RAM, an ESP32-S3 with 8 or 16 MB of flash leaves much more room. Do not pick a Nano's new bootloader option just to gain 2 KB if the board has the old one: the upload will fail.

Did this fix work for you?

Confirm it in one click: it will rise for the next developers stuck on the same error.

Keep it from coming back

  • Watch the percentages shown on every compile and react from 80%: you also need free RAM for the stack.
  • Get used to F() for every fixed text on AVR from the start of the project.
  • Choose the ESP32 partition scheme at the start of the project, before you have data in the file system.

Frequently asked questions

Does the F() macro reduce sketch size?

No. It saves RAM by keeping strings in flash, but the flash size stays about the same. For "Sketch too big", you must remove or slim down code.

What is the maximum sketch size on an Arduino Uno?

32,256 bytes of flash (32 KB minus the 512-byte bootloader) and 2,048 bytes of RAM.

Why does my 4 MB ESP32 reject a 1.4 MB sketch?

The default scheme splits the flash into two 1.25 MB app partitions (for OTA) plus a file system. Pick a scheme with a larger app partition.

Useful tools for this error

More Electronics & Arduino errors

All Electronics & Arduino errors →