I recently purchased an Esp32 and am doing some tests using Arduino IDE. In one of the tests, I am recording a lot of .txt files with some text inside them in the flash memory, however, I would like to know how I can check the remaining space in the flash memory. I'm checking the flash memory space with Serial.println(ESP.getFlashChipSize());, however, the returned value is always the same.

Is this the right command to check? Why is it always with the same value?

3 Answers 3


Is this the right command to check? Why is it always with the same value?

The only way that size can change is if you desolder the can from the top of the ESP32 module, then desolder the flash chip, and replace it with one that has a different capacity.

The free space is not a function of the flash chip. It is a function of the filesystem you are using to store your data - be that SPIFFS or FAT.

You should check the manual for the filesystem you are using to find what functions there are pertaining to space usage.


The file system on the ESP32 is stored in a portion of the flash memory, and managed by the SPIFFS (SPI Flash File System) library. You can use the SPIFFS.info() function to get information about the file system, including the total size and the used size.

Assuming you have SPIFFS:

#include <ESP.h>
#include <SPIFFS.h>

void setup() {
  // Initialize the SPIFFS file system
  if (!SPIFFS.begin(true)) {
    Serial.println("Initialization failed!");
  // size of the compiled program
  uint32_t program_size = ESP.getSketchSize();
  // size of the file system
  FSInfo fs_info;
  uint32_t file_system_size = fs_info.totalBytes;
  // used size of the file system
  uint32_t file_system_used = fs_info.usedBytes;
  // free size in the flash memory
  uint32_t free_size = ESP.getFlashChipSize() - program_size - file_system_size + file_system_used;
  Serial.print("Program size: ");
  Serial.println(" bytes");
  Serial.print("File system size: ");
  Serial.println(" bytes");
  Serial.print("File system used: ");
  Serial.println(" bytes");
  Serial.print("Free space: ");
  Serial.println(" bytes");

void loop() {
  // Do Nothing Here

Serial.println(ESP.getFlashChipSize()); don't return the physical flash size, it just returns the flash size that you have selected in the Arduino IDE Flash size. Just try to set Flash size "2MB (16Mb)" And the result is '2097152'

  • And if you want a bigger file system size, you can create your own partition table. Look at partitions.csv
    – whogarden
    Commented Nov 18, 2021 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.