Build on your computer
Here is Blink, a sketch that flashes the LED on pin 13. To the chip it is just letters. The chip only runs machine code: numbers in its flash memory. A toolchain, a set of programs on your computer, does the translating.
First the Arduino tools make the sketch proper C++. They add #include <Arduino.h>, which declares digitalWrite and delay, and a one-line declaration (a prototype) for each of your functions. The result is Blink.ino.cpp.
The compiler, avr-g++, turns the C++ into AVR machine code, saved in an object file (.o). It runs on your laptop but writes code for a different processor, the ATmega328P: that is called a cross-compiler.
Your .o calls digitalWrite and delay but does not contain them. They live in the core library, compiled once into core.a. The linker joins the pieces, drops unused ones, and gives every function its address in flash.
avr-objcopy copies the program's bytes into a .hex file: the same bytes and addresses, written as text. Then avr-size checks the fit. On the Uno a sketch may use at most 32,256 bytes of flash.
Flash it onto the chip
Now avrdude, the uploader, opens the USB port and sends the bytes at 115,200 bits per second. On the board, a second small chip, the ATmega16U2, turns USB into a plain serial line for the ATmega328P.
First the ATmega16U2 pulses the chip's reset line. After reset the Uno starts in the bootloader: a 512-byte program kept at the top of flash, at 0x7E00. Its one job is to receive a new program.
Flash is written in pages of 128 bytes, so the bootloader collects 128 bytes, then writes one page: page 0 at 0x0000, page 1 at 0x0080, and so on. 32,768 bytes of flash make 256 pages.
Then avrdude reads the flash back and compares it with the .hex file, byte by byte. If one byte differs it reports an error. Its -V option turns this check off, trading safety for speed.
Run
The bootloader jumps to address 0x0000 and your program starts: setup(), then loop() again and again. Pin 13 goes HIGH, then LOW, once a second. Flash keeps the program with the power off.
What happens
;; step 1/10 · source
board Arduino Uno R3 (chip: ATmega328P)
sketch Blink.ino, plain text
the chip runs machine code only: numbers in flash
toolchain the programs that turn text into those numbers
// Blink, for the Arduino Uno R3: the on-board LED is on pin 13
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
The card shows only loop(), with the pin written as 13. The real example writes LED_BUILTIN, which is pin 13 on the Uno, and setup() calls pinMode(LED_BUILTIN, OUTPUT). The commands are shortened. The Arduino tools also pass warnings, include paths and link-time optimisation (-flto), compile the core's own files, and run each step for you when you press Upload.