double and float

What Is the Size of a float Data Type?

On most common systems a float is 4 bytes with about 6 or 7 significant digits. Learn why the size can vary across compilers and how to check it with sizeof.

On this page
  1. Short answer
  2. Why the standard doesn’t fix the size
  3. Checking the size with sizeof
  4. What 4 bytes means for precision
  5. float, double and long double compared
  6. Writing float values
  7. Printing a float with printf
  8. Key takeaways

Short answer

On most common systems, a float takes 4 bytes, or 32 bits, and holds about 6 or 7 significant decimal digits. The C and C++ standards don’t set that exact size, though. The compiler and platform decide it, so check it with sizeof when it matters.

Why the standard doesn’t fix the size

The standards describe what a float must be able to do, not how many bytes it uses. The main rule is that double must provide at least as much precision as float, and long double at least as much as double.

Like the other primitive data types in c, float gets its size from the platform. Most current compilers on common hardware use the IEEE 754 single-precision format for float, which is 4 bytes, so that is the size you’ll usually see.

Checking the size with sizeof

#include <iostream>

int main() {
    std::cout << "float: " << sizeof(float) << " bytes\n";
    std::cout << "double: " << sizeof(double) << " bytes\n";
}

On a typical desktop, this prints 4 bytes for float and 8 bytes for double. sizeof returns a std::size_t, which std::cout prints as a plain number.

In C, print the result with %zu:

#include <stdio.h>

int main(void) {
    printf("%zu\n", sizeof(float));   // usually 4
    return 0;
}

For how the operator itself works, see the sizeof function in c.

What 4 bytes means for precision

Because a float holds about 6 or 7 significant digits, numbers that differ beyond that can end up stored as the same value. The number 16777216 is 2 to the power of 24. The next whole number, 16777217, can’t be stored in a float, so adding 1 changes nothing:

#include <iostream>

int main() {
    float big = 16777216.0f;   // 2^24
    float next = big + 1.0f;   // 16777217 can't be stored exactly

    std::cout << std::boolalpha << (next == big) << '\n';   // true
}

If your calculations need more digits, use double, which holds about 15.

float, double and long double compared

Type Typical size Significant decimal digits
float 4 bytes About 6 to 7
double 8 bytes About 15
long double Depends on the platform At least as many as double

A float is less precise, but it uses half the memory of a double. That matters for large arrays.

Writing float values

A literal with a decimal point is a double unless you add an f suffix:

float a = 3.5f;   // float literal
double b = 3.5;   // double literal

Printing a float with printf

printf takes a variable number of arguments, so a float is promoted to double before the call. That means %f prints a float correctly:

#include <stdio.h>

int main(void) {
    float ratio = 0.5f;
    printf("%f\n", ratio);   // 0.500000
    return 0;
}

Key takeaways

  • A float is usually 4 bytes with about 6 or 7 significant digits.
  • The standard sets minimum precision rules, and the platform sets the exact size.
  • Check the size with sizeof rather than assuming it.
  • Use double when a float doesn’t have enough digits.

The complete guide to double and float

What double Does in C++
Read the guide

Keep exploring

Guides from other topics

All topics →

The sizeof Operator in C++

Learn how the sizeof operator in C++ works: what it returns in bytes, how it handles arrays, pointers and structs, and common mistakes to avoid.

sizeof 6 min read

Bitwise XOR in C++

Learn how the bitwise XOR operator (^) in C++ works, with a truth table, code examples, and common uses such as toggling bits and swapping values.