How I2C Addressing, ACK and Clock Stretching Work
See how an I2C address byte is built, what ACK and NACK mean at each byte, why a slave holds SCL low, and how to avoid the 7-bit versus 8-bit mix-up.

Three ideas make I2C work on two wires: every device has an address that the controller sends first, every byte is answered with an acknowledge that tells the sender whether anyone is listening, and a slow device can make the controller wait by holding the clock line low. Each is simple alone, and each is the source of a classic bug: a sensor that "is not found" because the address was quoted in a different form, a read that hangs because the last byte was acknowledged, a measurement that returns garbage because the controller ignored a slave that was still busy. This post explains the three with bit-level examples and short C functions, following the NXP I2C-bus specification and user manual UM10204. The wider bus is covered in the guide to I2C in this cluster.
The address byte
After a START condition the controller sends one byte that names the target device and the direction of the transfer. Seven of its eight bits are the address, and the least significant bit is the direction:
| Bit 7 | 6 | 5 | 4 | 3 | 2 | 1 | Bit 0 |
|---|---|---|---|---|---|---|---|
| A6 | A5 | A4 | A3 | A2 | A1 | A0 | R/W |
R/W = 0 means the controller will write to the device, and R/W = 1 means it will read. So the byte that goes on the wire is the 7-bit address shifted left by one with the direction bit in the free position. For a device at 7-bit address 0x68:
write:
(0x68 << 1) | 0=0xD0read:
(0x68 << 1) | 1=0xD1
A small program makes the conversion explicit, which is worth keeping as a helper:
#include <stdio.h>
#include <stdint.h>
static uint8_t addr_write(uint8_t addr7) { return (uint8_t)(addr7 << 1); }
static uint8_t addr_read(uint8_t addr7) { return (uint8_t)((addr7 << 1) | 1u); }
int main(void)
{
uint8_t addr7 = 0x68;
printf("7-bit 0x%02X -> write byte 0x%02X, read byte 0x%02X\n",
addr7, addr_write(addr7), addr_read(addr7));
uint8_t wire_byte = 0xD0;
printf("wire byte 0x%02X -> 7-bit address 0x%02X, %s\n",
wire_byte, wire_byte >> 1, (wire_byte & 1) ? "read" : "write");
return 0;
}7-bit 0x68 -> write byte 0xD0, read byte 0xD1
wire byte 0xD0 -> 7-bit address 0x68, writeThe 7-bit versus 8-bit trap
Datasheets and libraries disagree on which form they print. A datasheet that says "the device address is 0xD0" is quoting the write byte; one that says "0x68" is quoting the 7-bit address. Arduino's Wire library, the Raspberry Pi Pico SDK and ESP-IDF all take the 7-bit address, as does the Linux i2cdetect tool. The STM32 HAL takes the 8-bit form: you pass 0x68 << 1. If a device is "not found", try both forms, 0x68 and 0xD0, before suspecting the wiring. A symptom of the mistake in the other direction is a device appearing at twice or half its documented address in a scan.
Reserved addresses
Seven bits give 128 values, but the specification reserves some:
| Address range | Use |
|---|---|
0x00 to 0x07 | General call, START byte, CBUS, different bus formats, high-speed mode code |
0x78 to 0x7B | 10-bit addressing |
0x7C to 0x7F | Reserved |
Usable 7-bit addresses run from 0x08 to 0x77, which is 112 addresses. A scanner should not probe the reserved ranges; some of them trigger special behavior in devices on the bus.
Address pins
Many devices fix the upper bits of their address and let the lower bits follow pins. An EEPROM such as the 24C32 has the fixed bits 1010 and three address pins A2 A1 A0, which gives eight addresses from 0x50 to 0x57. A sensor with one ADDR pin typically offers two addresses, for example 0x68 and 0x69 for the MPU-6050 with AD0 low or high. A floating address pin gives an undefined address, so tie each address pin high or low.
The acknowledge
After every byte, the sender releases SDA for the ninth clock pulse. The receiver answers:
ACK: the receiver pulls SDA low during the ninth clock. It means "received, send more or continue".
NACK: the receiver leaves SDA high. It means "not received, or enough".
The meaning depends on who is sending and where in the transaction it happens.
| After which byte | Who answers | NACK means |
|---|---|---|
| Address byte | The addressed device | No device with that address, or it is busy |
| Data byte the controller writes | The device | The device cannot accept more, or rejected that register or value |
| Data byte the device sends | The controller | "That was the last byte I want"; the device must stop and release SDA |
The last row is the one that causes hangs. When the controller reads several bytes from a device, it acknowledges every byte except the last, and it NACKs the last byte. That NACK tells the device to stop driving SDA so the controller can send a STOP. A controller that ACKs the final byte makes the device send another, and then the device holds SDA low as it outputs the next bit, which blocks the STOP condition and can freeze the bus.
A model of a read shows which acknowledge belongs to whom. Reading three bytes from a device:
S | addr+R | ACK(device) | byte1 | ACK(controller) | byte2 | ACK(controller) | byte3 | NACK(controller) | PEvery ACK from the device after the address, and ACK from the controller after bytes 1 and 2, then the closing NACK. Count them in your driver: with n bytes read, n - 1 ACKs and one NACK.
Wired-AND: why ACK works on one wire
SDA is open-drain: any device can pull it low, and nobody drives it high. The line's value is therefore the logical AND of every device's output, where "1" means "released". The truth table for a single bit time with two devices:
| Device A | Device B | Line |
|---|---|---|
| released (1) | released (1) | 1 |
| released (1) | pulling low (0) | 0 |
| pulling low (0) | released (1) | 0 |
| pulling low (0) | pulling low (0) | 0 |
That is why the receiver can answer on the same wire the sender used: the sender releases SDA for the ninth clock, and the receiver pulls it low if it wants to ACK. It is also the reason a single stuck device can block the bus, since it keeps the line low whatever others do.
Clock stretching
The clock line SCL is also open-drain. The controller drives it low and releases it, and a pull-up raises it. A slave can hold SCL low after the controller has released it, which stretches the clock: the controller wants SCL high, sees it still low and must wait until the slave lets go. Slaves use it to say "I am not ready for the next bit".
The sequence for one clock pulse with a stretching slave:
The controller releases SCL (stops pulling it low).
A slave that needs time keeps pulling SCL low.
The controller reads SCL back. While it is low, the controller waits.
The slave releases SCL, the pull-up raises it, and the controller sees it high and continues with the clock pulse.
Where it commonly happens: after the address byte, when a slave microcontroller must run its interrupt handler to prepare a response; between bytes when it needs time to process; and in a sensor that is completing a measurement and cannot return data until it finishes. A controller that does not watch SCL, a bit-banged one that writes SCL high and immediately samples SDA, reads before the data is valid.
A bit-banged controller must therefore read SCL back before it proceeds:
#include <stdint.h>
extern void scl_release(void); /* let the pull-up raise SCL */
extern int scl_read(void); /* read the actual level */
extern void delay_us(uint32_t us);
/* Release SCL and wait until it is really high. Returns 0 on success, -1 on timeout. */
int scl_release_and_wait(uint32_t timeout_us)
{
scl_release();
while (scl_read() == 0) {
if (timeout_us-- == 0) {
return -1; /* a slave held SCL low too long */
}
delay_us(1);
}
return 0;
}A hardware I2C peripheral does this automatically, and some have a timeout flag if SCL stays low beyond a limit. SMBus defines that limit as 35 milliseconds; a slave stretching longer than that is considered hung and the controller should reset it.
The timeout in the code above is essential. A slave that crashed while holding SCL low would otherwise block the controller forever.
The cost of stretching
Stretching slows every device on the bus, because the bus runs at the speed of the stretching device whenever it stretches. A slave that stretches by 100 microseconds after every byte turns a 400 kHz bus into one that effectively moves about 7,500 bytes per second rather than 44,000. Some microcontrollers' I2C peripherals have known bugs with stretching, which is one reason that a slave built from a microcontroller should answer from a register map prepared ahead of time instead of computing the answer during the transaction.
Putting the three together: a probe
A probe, used by scanners, combines all of it: send a START, send the address with the write bit, check the ACK and send a STOP. The result tells you whether a device is present, with no data transferred.
#include <stdbool.h>
#include <stdint.h>
extern void i2c_start(void);
extern void i2c_stop(void);
extern bool i2c_write_byte(uint8_t b); /* returns true if the receiver ACKed */
bool i2c_device_present(uint8_t addr7)
{
i2c_start();
bool acked = i2c_write_byte((uint8_t)(addr7 << 1)); /* address + write */
i2c_stop();
return acked;
}On a bus with a device at 0x68, i2c_device_present(0x68) returns true and i2c_device_present(0x69) returns false, because nobody answers the second address, SDA stays high during the ninth clock and the controller sees a NACK.
Where this simple model stops
10-bit addresses use a two-byte address with a reserved first byte pattern (
11110xx) and exist on few devices.General call (
0x00) addresses every device at once; devices may respond to commands such as reset, and a probe at this address can cause side effects.A NACK is not always "absent". A busy EEPROM during its write cycle NACKs its address, and a device in reset may as well. Retry before concluding.
Stretching is optional. A controller peripheral that does not support it, or one configured with the stretching disabled, loses data on slaves that stretch.
Multi-master buses add arbitration, where two controllers start together and the one that loses stops sending; the guide covers it.


