What is the impact of Struct Padding and Memory Alignment?
Updated Apr 28, 2026
Short answer
Go pads structs to align memory addresses for faster CPU access, which can waste memory if fields are ordered poorly.
Deep explanation
CPUs read memory in word-sized chunks (e.g., 8 bytes on a 64-bit system). If an int8 (1 byte) is followed by an int64 (8 bytes), Go adds 7 bytes of invisible padding so the int64 starts on a clean 8-byte boundary. Sorting struct fields from largest to smallest minimizes padding and shrinks the overall struct size.
Unlock with a Pro subscription to view this section.
View pricingReal-world example
No real-world example available yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProCommon mistakes
No common mistakes listed yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProFollow-up questions
No follow-up questions available yet.
Unlock with a Pro subscription to view this section.
Upgrade to Pro