Structure Padding Isn’t Wastage of Memory — It’s a Hardware Requirement

Published: (December 31, 2025 at 12:02 PM EST)
2 min read
Source: Dev.to

Source: Dev.to

Have you ever manually calculated the size of a struct, only to find that sizeof returns a larger number? You aren’t crazy, and the compiler isn’t broken. In this guide we’ll decode structure padding, explain why it happens, why your CPU loves it, and how to optimise it for embedded systems.

Table of Contents

What Is a Structure

  • A structure in C is a user‑defined data type that lets programmers group together values of different types under a single name.
  • The items in the structure are called members and they can be of any valid data type.
  • A structure is defined with the struct keyword, followed by the structure’s name and a list of members inside curly braces {}.
struct Point {
    int   x;
    int   y;
};

How Structures Are Stored in Memory

Consider the following structure:

#include <stdio.h>

struct example {
    char a;   // 1 byte
              // 3 bytes of padding inserted here
    int  b;   // 4 bytes
    char c;   // 1 byte
              // 3 bytes of padding inserted here
};

int main(void) {
    printf("size of struct = %zu bytes\n", sizeof(struct example));
    return 0;
}

Running the program prints:

size of struct = 12 bytes

Even though the members add up to only 6 bytes, the compiler reports 12 bytes.
The reason is the way the compiler maps the

Back to Blog

Related posts

Read more »