C struct layout and padding calculator

Your packed log record is bigger than you expected and RAM is tight. Paste a C struct and get real byte offsets, inserted padding, and the saving from reordering members widest-first.

Open the calculator in EM·LINKBelow is a worked example. The working calculator runs free in EM·LINK.

Worked example

Example inputs

struct log_rec { uint8_t flags; uint32_t timestamp; uint8_t channel; float value; uint16_t crc; };
32-bit ARM (AAPCS)▾
1000records

Example result

Struct size20 bytes

8 bytes are padding. Widest first it is 12 bytes, saving 8000 bytes over 1000 records.

MemberOffsetSizePadding after
flags013
timestamp440
channel813
value1240
crc1622

Reordered: timestamp, value, crc, flags, channel.

Your struct is parsed in your browser. Nothing is sent to us.

Run it with your own values

The working calculator is C Struct Layout & Padding in EM·LINK, our free browser tool. The button opens it directly.

Open in EM·LINK

How to read the result

Example: uint8, uint32, uint8, float, uint16 on 32-bit ARM is 20 bytes with 8 bytes of padding. Widest-first it is 12 bytes. Over 1000 log records that is 8 kB of RAM.

How this is calculated

Each member starts at the next multiple of its own alignment, and the struct size rounds up to its widest member so that arrays stay aligned.

offset(m) = next multiple of align(m) struct size rounds up to widest member alignment 32-bit ARM: long and pointer = 4 bytes x86-64 / AArch64: long and pointer = 8 bytes
flagspadtimestampchpadvaluecrcpadtimestampvaluecrcflagschAs written, 32-bit ARM: 20 bytes, 8 of them paddingWidest first: 12 bytes, no paddingEach cell is one byte.

The full derivation, step by step, is in the EM·LINK documentation.

Calculated per C ABI natural alignment rules in the Arm ABI documents (AAPCS) and the System V ABI for x86-64. These tools are an engineering aid, not a certification.

Next step

Shipping hundreds of units? Get OTA updates and remote config without building it yourself.

Common questions

Why is my struct bigger than the sum of its members?

Each member aligns to its natural size and the struct pads to its widest member.

Should I use packed structs?

Reordering usually saves the same space without unaligned-access penalties.

Which ABIs are supported?

32-bit ARM and 64-bit x86-64 or AArch64.