← All posts
November 17, 2026 · 3 min read

How a double is stored in C++: sign, exponent and mantissa

The real eight bytes of -6.25 in memory, read as 64 bits and split into the IEEE-754 fields: 1 sign bit, 11 exponent bits, 52 mantissa bits.

How a double is stored comes down to three fields packed into 64 bits: one sign bit, eleven exponent bits and fifty-two mantissa bits. That layout is IEEE-754 double precision, and it is what every double uses on x86-64. Here it is on real bytes, for the value -6.25.

This is the written version of Understanding C++ #5. Everything below comes from one real program, compiled with g++ -std=c++20 -Wall -O2 on x86-64 Linux.

What does a double look like in memory?

double d = -6.25; takes eight bytes. In this run d lived at 0x7fffffffc040, and the program printed its bytes in address order:

double d = -6.25 at 0x7fffffffc040: its eight bytes are 00 00 00 00 00 00 19 c0

00 00 00 00 00 00 19 c0

x86-64 is little-endian: the lowest byte sits at the lowest address. So the byte that matters most, c0, is the last one, at 0x7fffffffc047.

How do the 64 bits split into fields?

Read the bytes top byte first and you get one 64-bit pattern: c0 19 00 00 00 00 00 00. The program gets the same pattern as an integer with std::bit_cast<std::uint64_t>(d), which copies the bits without changing them. In binary:

1 10000000001 1001000000000000000000000000000000000000000000000000
s exponent    mantissa

Read top byte first, the 64 bits split into sign, exponent and mantissa

field bits position raw value here
sign 1 bit 63 1
exponent 11 bits 62 to 52 1025
mantissa 52 bits 51 to 0 0x9000000000000

The program pulls each field out with a shift and a mask: u >> 63, (u >> 52) & 0x7FF, and u & 0xFFFFFFFFFFFFF. 0x7FF is eleven 1 bits, and 0xFFFFFFFFFFFFF is fifty-two.

What does the sign bit do?

It is the whole sign, nothing more. 1 means negative, 0 means positive. -6.25 and 6.25 differ in that one bit only; the other 63 are the same. That is also why a double has both +0.0 and -0.0.

Why is the exponent 1025 and not 2?

The eleven exponent bits are 10000000001, which is 1025. The exponent is stored with a bias of 1023, so that the field itself is never negative: the real power of two is 1025 - 1023 = 2.

The 11 exponent bits 10000000001 are 1025

A field of 1023 means 2⁰, 1022 means 2⁻¹, and so on. The values 0 and 2047 are reserved for zero, subnormal numbers, infinity and NaN.

What is in the mantissa?

The last fifty-two bits hold 1001, then forty-eight zeros. The program prints them as one hex number, 9000000000000: the top four bits are 1001, which is hex 9.

The 52 mantissa bits are 1001 followed by 48 zeros

These are the bits after the binary point. For any normal number the bit before the point is always 1, so it is not stored at all; it is implied. Put it back and the significand is 1.1001 in binary.

How do the fields give -6.25?

Multiply by 2 to the power of the exponent, which is 2² = 4. Shifting the binary point two places right turns 1.1001 into 110.01: that is 4 + 2 + 0.25 = 6.25. The sign bit is 1, so the value is -6.25, which is what the program prints first.

1.1001 in binary times 2 squared is 110.01; with sign bit 1 that is -6.25

In general a normal double is (-1)^sign × 1.mantissa × 2^(exponent - 1023).

The program and its output

#include <bit>
#include <cstdint>
#include <cstdio>
int main() {
    double d = -6.25;
    auto* b = (unsigned char*)&d;
    std::printf("%g at %p:", d, (void*)b);
    for (int i = 0; i < 8; i++)
        std::printf(" %02x", b[i]);
    auto u = std::bit_cast<std::uint64_t>(d);
    auto s = u >> 63;                // 1 bit
    auto e = (u >> 52) & 0x7FF;      // 11 bits
    auto m = u & 0xFFFFFFFFFFFFF;    // 52 bits
    std::printf("\n%lu %lu %lx\n", s, e, m);
}
-6.25 at 0x7fffffffc040: 00 00 00 00 00 00 19 c0
1 1025 9000000000000

The address comes from a run with address randomisation turned off (setarch -R); on your machine it will differ. The bytes and the fields are the same on any machine with IEEE-754 doubles and little-endian byte order. %lu matches std::uint64_t on 64-bit Linux, where it is unsigned long; -Wall prints no warning.

Every double: one sign bit, eleven exponent bits, fifty-two mantissa bits.

Try it

What is the exponent field of 12.5? Write 12.5 as 1.something in binary times a power of two, add the bias, then change -6.25 in the program to check your answer.