seniorGolang

How does Go handle Memory Alignment and Size of Structs?

Updated Apr 28, 2026

Short answer

The physical size of a struct in Go depends heavily on the ordering of its fields due to alignment guarantees.

Deep explanation

Different architectures require primitive types to be aligned on specific byte boundaries (e.g., an 8-byte int64 must start at an address divisible by 8). Go inserts padding bytes to satisfy these hardware rules. To optimize memory footprint, especially for structs cached by the millions, fields should be sorted from largest byte size to smallest.

Unlock with a Pro subscription to view this section.

View pricing

Real-world example

No real-world example available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Common mistakes

No common mistakes listed yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Follow-up questions

No follow-up questions available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

More Golang interview questions

View all →