Memory Allocation on Arduino Boards

Learn how the memory on Arduino boards work.

There are three potential pools of memory in the microcontrollers used on Arduino boards:

  • Flash memory (program space), is where the Arduino sketch is stored.

  • SRAM (static random access memory) is where the sketch creates and manipulates variables when it runs.

  • EEPROM is memory space that programmers can use to store long-term information.

Flash memory and EEPROM memory are non-volatile (the information persists after the power is turned off). SRAM is volatile and will be lost when the power is cycled.

Memory on Arduino Nano boards

The nRF52840 (datasheet) chip found on the Nano 33 BLE Sense and Nano 33 BLE has the following amounts of memory:

Memory TypeSize
Flash1mb
SRAM256kb

The SAMD21G18A (datasheet) chip found on the Nano 33 IoT has the following amounts of memory:

Memory TypeSize
Flash1mb
SRAM256kb

The SAMD21G18A (datasheet) chip found on the Nano RP2040 Connect has the following amounts of memory:

Memory TypeSize
Flash16mb
SRAM264kb

The ATmega4809 (datasheet) chip found on the Nano Every has the following amounts of memory:

Memory TypeSize
Flash48kb
SRAM6kb
EEPROM256 bytes

The ATmega328 (datasheet) chip found on the Nano has the following amounts of memory:

Memory TypeSize
Flash32kb
SRAM2kb
EEPROM1kb

Memory on Arduino MKR boards

The SAMD21G18A (datasheet) chip found on the MKR WiFi 1000, MKR FOX 1200, MKR GSM 1400, MKR NB 1500, MKR Vidor 4000, MKR WAN 1300, MKR WAN 1310, MKR WiFi 1010 and MKR Zero has the following amounts of memory:

Memory TypeSize
Flash256kb
SRAM32kb

Memory on Arduino Pro boards

The ST STM32H747XI (datasheet) chip found on the Portenta H7, Portenta H7 Lite and Portenta H7 Lite Connected has the following amounts of memory:

Memory TypeSize
Flash2mb
SRAM1mb

Memory on Arduino Classic boards

The ATmega328P (datasheet) chip found on the UNO R3 and UNO Mini has the following amounts of memory:

Memory TypeSize
Flash32kb
SRAM2kb
EEPROM1kb

The ATmega4809 (datasheet) chip found on the UNO WiFi Rev2 has the following amounts of memory:

Memory TypeSize
Flash48kb
SRAM6kb
EEPROM256 bytes

The ATmega32U4 (datasheet) chip found on the Yún Rev2, Leonardo and Micro has the following amounts of memory:

Memory TypeSize
Flash32kb
SRAM2.5kb
EEPROM1kb

The Atmel SAM3X8E (datasheet) chip found on the Due has the following amounts of memory:

Memory TypeSize
Flash512kb
SRAM96kb

The ATmega2560 (datasheet) chip found on the Mega 2560 Rev3 has the following amounts of memory:

Memory TypeSize
Flash256kb
SRAM8kb
EEPROM4kb

Notice that with boards that do not have a lot of SRAM available, like the UNO. It's easy to use it all up by having lots of strings in your program. For example, a declaration like:

1char message[] = "I support the Cape Wind project.";

puts 33 bytes into SRAM (each character takes a byte, plus the '\0' terminator). This might not seem like a lot, but it doesn't take long to get to 2048, especially if you have a large amount of text to send to a display, or a large lookup table, for example.

If you run out of SRAM, your program may fail in unexpected ways; it will appear to upload successfully, but not run, or run strangely. To check if this is happening, you can try commenting out or shortening the strings or other data structures in your sketch (without changing the code). If it then runs successfully, you're probably running out of SRAM. There are a few things you can do to address this problem:

  • If your sketch talks to a program running on a (desktop/laptop) computer, you can try shifting data or calculations to the computer, reducing the load on the Arduino.

  • If you have lookup tables or other large arrays, use the smallest data type necessary to store the values you need; for example, an int takes up two bytes, while a byte uses only one (but can store a smaller range of values).

  • If you don't need to modify the strings or data while your sketch is running, you can store them in flash (program) memory instead of SRAM; to do this, use the PROGMEM keyword.

Contribute to Arduino

Join the community and suggest improvements to this article via GitHub. Make sure to read out contribution policy before making your pull request.

Missing something?

Check out our store and get what you need to follow this tutorial.