C Struct Padding Calculator — offsets, padding and size
Paste a C struct to see member offsets, inserted padding and total size for 32-bit and 64-bit targets — and how to reorder it smaller.
Example: This struct is 32 bytes with 16 of padding, or 16 bytes if the members are reordered.
Check it against real silicon
Chiprun runs your firmware on an emulated microcontroller and hands back the UART output, so you can confirm these numbers rather than trusting them.
Formula
each member starts at a multiple of its alignment; the struct is padded to its strictestWorked example
This struct is 32 bytes with 16 of padding, or 16 bytes if the members are reordered.
each member starts at a multiple of its own alignment
a @ 0, b @ 4, c @ 8, d @ 16, e @ 24
32 bytes total
struct size rounds up to its strictest alignment
round 26 up to a multiple of 8
32 bytes
Frequently asked questions
Why is my struct bigger than the sum of its members?
Padding. Each member must start at an offset that is a multiple of its own alignment, so the compiler inserts gaps. The struct is then padded at the end too, so that an array of them keeps every element aligned.
How do I make a struct smaller?
Reorder the members largest-alignment-first. It costs nothing at runtime and often removes most of the padding — this tool shows both layouts and the saving. Packing with a pragma also works but makes access unaligned, which is slower on x86 and faults on some ARM cores.
Why is there padding at the end of a struct?
So arrays work. If a struct contains an 8-byte member, every element in an array of it must start on an 8-byte boundary — which means the struct's size has to be a multiple of 8, even if the last member ends earlier.
Does this layout change between platforms?
Yes. `long` and pointers are 4 bytes on 32-bit and 8 on 64-bit, which shifts every subsequent offset. If a struct crosses a wire or a file format, use the fixed-width intN_t types and check the layout on both ends.
Related tools
Stack Size Estimator
Estimate worst-case stack depth from call nesting, locals and interrupt frames.
Firmware
Hex, Binary & Decimal Converter
Convert between hex, binary, decimal, octal and ASCII, with width-aware bit grids and endianness swapping.
Firmware
IEEE 754 Float Converter
Convert between decimal, hex and binary float32/float64, with the sign, exponent and mantissa fields broken out.
Firmware
Register Bitfield Decoder
Paste a register value and a field layout to get a decoded table — with presets for common STM32 and AVR registers.
Firmware
Bitwise Operation Calculator
AND, OR, XOR, NOT and shifts with a live bit grid so you can see exactly which bits moved.
Firmware
CRC Calculator
CRC-8, CRC-16 (CCITT, Modbus, XMODEM) and CRC-32 over hex or ASCII input, with the polynomial and shift steps explained.
Firmware