How to convert Kubernetes CPU and memory units
- Type a quantity exactly as it appears in your manifest:
500m,0.25,1.5Gi,512M. - Pick what it is for — CPU, memory or storage. The same text means very different things:
128mis a fair CPU request and an impossible memory limit. - Read the form the API server stores, the exact bytes or millicores, and the conversions. When a note offers a fix, its button puts the corrected value in.
Kubernetes quantity suffixes
A quantity is a number followed by an optional suffix, with no space. Decimal suffixes are powers of 1000, binary ones powers of 1024, and they are case-sensitive.
| Suffix | Multiplies by | Example |
|---|---|---|
m | milli, 10⁻³ | 500m |
(none) | 1 | 2 |
k | 10³ | 100k |
M | 10⁶ | 512M |
G | 10⁹ | 1G |
T | 10¹² | 1T |
Ki | 2¹⁰ = 1,024 | 64Ki |
Mi | 2²⁰ = 1,048,576 | 256Mi |
Gi | 2³⁰ = 1,073,741,824 | 2Gi |
Ti | 2⁴⁰ | 1Ti |
e | 10ⁿ, as an exponent | 1e3 |
The parser also accepts n (nano) and u (micro), and P, E, Pi, Ei at the large end.
What you write and what kubectl shows
The API server rewrites each quantity into a canonical spelling of the same amount. Every row below is computed with the same rules this tool uses:
| You write | Stored as | Kubernetes uses |
|---|---|---|
0.5 | 500m | 500m |
1000m | 1 | 1,000m |
1.5 | 1500m | 1,500m |
1.5Gi | 1536Mi | 1,610,612,736 bytes |
2048Ki | 2Mi | 2,097,152 bytes |
0.5Ki | 512 | 512 bytes |
1000k | 1M | 1,000,000 bytes |
1e3 | 1e3 | 1,000,000m |
Gotchas this tool checks for
Lowercase m on memory is milli, not mega
128m of memory is 0.128 bytes, rounded up to 1 byte. It passes validation, so the mistake only shows when the container cannot start or is killed at once. The tool flags it and offers 128Mi.
M and Mi are not the same amount
512M is 512,000,000 bytes; 512Mi is 536,870,912 bytes. Mixing them between a request and a limit, or between Kubernetes and a JVM or Node.js heap flag, leaves you a few percent short — more as the units grow.
M ≠ Mi1 of each decimal unit against its binary twin1G is 6.9% smaller than 1Gi, 1T 9.1% smaller than 1Ti.CPU in byte units, and CPU below a millicore
2Gi of CPU is two billion cores — a copy-paste from the memory line. And CPU is counted in whole millicores, so 0.5m becomes 1m. Both get a warning.
Capital K, B and spaces
1K, 512MB, 1GiB and 512 Mi are rejected by the API server. The tool says why and suggests the spelling Kubernetes accepts.
From one value to a whole Pod
A quantity is only half of the story: whether a container gets a request equal to its limit decides the Pod's QoS class, init and sidecar containers change what the scheduler reserves, and the HorizontalPodAutoscaler measures utilization against the request.
Verification
- Parsing, rounding and the canonical form follow
resource.Quantityink8s.io/apimachinery: the same grammar, the round-up to 1n, the int64 cap on binary values and the String() rules. The unit tests use vectors from itsquantity_test.go(0.1 → 100m, 1.5Gi → 1536Mi, 0.5Ki → 512, 1.1e3 → 1100). - Arithmetic is exact: values are held as whole nanounits in BigInt, so no floating-point rounding reaches a result.
- Bytes and millicores round up the way
Value()andMilliValue()do. - The engine runs in this tab; nothing you type is sent anywhere.