Source: https://mokxi.com/learn/arduino-eeprom
Updated: 2026-10-26

Learn

# Arduino EEPROM: memory that survives a reset

Beginner

Written by the Mokxi team, updated October 26, 2026

Start building free Open the editor

Or see every lesson.

- 455 parts on the bench
- 43 boards running now
- 1.00x real time, on every board

Click to open it in the editor

The EEPROM example on a simulated ATmega328P. Open the serial monitor and press reset: the start count goes up.

Everything in your sketch’s variables is gone the moment the Arduino resets or loses power. That is fine for most things, but not for a high score, a setting or a count you want to keep. For those, the Uno has 1024 bytes of EEPROM inside its chip: memory that keeps its contents with the power off.

The circuit above is just an Uno, because the EEPROM is inside the chip and there is nothing to wire. The sketch writes an int and a long, reads them back, and counts how many times it has started. Open the serial monitor, press the board’s reset, and the count goes up by one. It runs in your browser on the sketch below.

## Five calls cover everything

Include EEPROM.h and you get five calls. EEPROM.read(address) gives you one byte, from address 0 to 1023 on an Uno. EEPROM.write(address, value) stores one byte. EEPROM.update(address, value) stores it only if it is different from what is already there, which saves wear. EEPROM.put(address, value) stores a value of any type, an int, a long, a float or a struct, using as many bytes as it needs. EEPROM.get(address, variable) reads one back into a variable of the same type.

You choose the addresses yourself. An int is two bytes on an Uno and a long is four, so in the example the int lives at address 0, the long at address 2, and the start count at address 6. If two values overlap, one quietly overwrites the other, so it pays to write the addresses down as constants at the top of the sketch.

## The example, step by step

The sketch puts 2000 at address 0 and 65539 at address 2, then reads both back into fresh variables. The serial monitor prints "int read back: 2000" and "long read back: 65539". 65539 needs more than two bytes, which is why it is a long and why put() and get() are the easy way to store it.

Then it reads one byte at address 6, adds one and saves it with update(). A brand new EEPROM reads 255 at every address, so the sketch treats 255 as zero. The first run prints "this sketch has started 1 time". Press reset and it prints "this sketch has started 2 times", because the byte at address 6 kept its value.

The setup(), from the EEPROM example

## It wears out, so write with care

Each EEPROM byte on the ATmega328P is rated for about 100,000 writes. That sounds like a lot, but a sketch that writes to the same address on every loop can use it up in minutes. Reading is free; only writing wears it.

So write only when something changes. Use update() instead of write(), because it skips the write when the value is already the same; put() already works this way. Save a setting when the user changes it, not on a timer. And never put an EEPROM write inside loop() with no condition around it.

Writes are also slow, about 3.3 milliseconds a byte on the Uno, so writing a big struct in a hurry can make a sketch stutter.

## On other boards

The size depends on the chip. The Uno and the Nano have 1 KB, and the Mega 2560 has 4 KB. On those AVR boards Mokxi uses the chip’s own EEPROM, and it keeps its bytes across a reset, as you can see above.

The ESP32, the Pico and most newer boards have no EEPROM at all. Their EEPROM library pretends to have one by keeping a copy in flash memory. On those boards in Mokxi, EEPROM.h compiles and works while the sketch runs, but it keeps 4 KB in RAM, so a reset clears it. On a real ESP32 you also need EEPROM.begin(size) before you use it and EEPROM.commit() to save, and the Preferences library is the usual choice for new code.

## Try it in the editor

Change bigIn to 123456 and run it. Then store a float with put() at address 7 and read it back with get(). Notice that a float is four bytes, so the next free address after it is 11.

Turn the count into something useful: a sketch that remembers the brightness of an LED between resets, saved with update() only when a button changes it.

## Common mistakes

Writing on every loop. It wears the EEPROM out. Write only when the value changes.

Overlapping addresses. A long at address 2 uses addresses 2, 3, 4 and 5. Put the next value at 6, not 3.

Forgetting that a blank byte is 255. The first time a sketch runs, every address reads 255, not 0. Check for it, as the example does.

Using write() for a number bigger than 255. write() stores one byte and throws the rest away. Use put() and get() for anything larger.

Reading with a different type than you wrote. put() an int and get() it into a long, and you read two bytes of something else along with it.

## Questions

How much EEPROM does an Arduino Uno have?

1024 bytes, at addresses 0 to 1023. The Nano has the same, and the Mega 2560 has 4096.

What is the difference between EEPROM.write and EEPROM.put?

write() stores exactly one byte. put() stores a whole value of any type, using as many bytes as that type needs, and only writes the bytes that changed. Read them back with read() and get() to match.

How many times can I write to Arduino EEPROM?

About 100,000 times per byte on the Uno’s ATmega328P. Reads do not count. Use update() or put() so a write that would not change anything is skipped.

Does the EEPROM survive uploading a new sketch?

Usually, yes. Uploading rewrites the program memory, not the EEPROM, unless the board was set to erase it. In Mokxi, the AVR boards keep their EEPROM across the reset button.

Related

## Keep going

Arduino State Machine: A Four-State Reaction Game How to Debug Arduino Code: Prints to Breakpoints Arduino DS3231 Clock With a TM1637 Display Microcontroller Lab Viva Questions, With Answers Arduino Struct: Group Values, With Examples ESP32 Preferences Library: Save Settings, Example The libraries that compile in Mokxi The Arduino Uno simulator A voting machine that keeps its votes in EEPROM Beginner The project page, with the full sketch Beginner

## Build this for real

Open the editor, change a value and watch the number move with it. Nothing to install, and no account needed.

Start building free Open the editor
