---
name: "libressl-BN_num_bytes"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-BN_num_bytes"
---

# libressl-BN\_num\_bytes(3)

get BIGNUM size

## NAME

**BN\_num\_bits\_word**, **BN\_num\_bits**, **BN\_num\_bytes** – get BIGNUM size

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/bn.h\>**

*int*\

**BN\_num\_bits\_word**(*BN\_ULONG w*);

*int*\

**BN\_num\_bits**(*const BIGNUM \*a*);

*int*\

**BN\_num\_bytes**(*const BIGNUM \*a*);

## DESCRIPTION

**BN\_num\_bits\_word**() returns the number of significant bits in *w*, that is, the minimum number of digits needed to write *w* as a binary number. Except for an argument of 0, this is

floor(log2(*w*)) + 1.

*BN\_ULONG* is a macro that expands to *unsigned* *long* (= *uint64\_t*) on \_LP64 platforms and *unsigned* *int* (= *uint32\_t*) elsewhere.

**BN\_num\_bits**() returns the number of significant bits in the value of the *BIGNUM \*a*, following the same principle as **BN\_num\_bits\_word**().

**BN\_num\_bytes**() is a macro that returns the number of significant bytes in *a*, i.e. the minimum number of bytes needed to store the value of *a*, that is, **BN\_num\_bits**(*a*) divided by eight and rounded up to the next integer number.

## RETURN VALUES

**BN\_num\_bits\_word**() returns the number of significant bits in *w* or 0 if *w* is 0. The maximum return value that can occur is BN\_BITS2, which is 64 on \_LP64 platforms and 32 elsewhere.

**BN\_num\_bits**() returns the number of significant bits and **BN\_num\_bytes**() the number of significant bytes in *a*, or 0 if the value of *a* is 0.

## SEE ALSO

BN\_new(3), BN\_security\_bits(3), DH\_size(3), DSA\_size(3), RSA\_size(3)

## HISTORY

**BN\_num\_bytes**() and **BN\_num\_bits**() first appeared in SSLeay 0.5.1. **BN\_num\_bits\_word**() first appeared in SSLeay 0.5.2. These functions have been available since OpenBSD 2.4.

## CAVEATS

Some have tried using **BN\_num\_bits**() on individual numbers in RSA keys, DH keys and DSA keys, and found that they don't always come up with the number of bits they expected (something like 512, 1024, 2048, ...). This is because generating a number with some specific number of bits doesn't always set the highest bits, thereby making the number of *significant* bits a little smaller. If you want to know the "key size" of such a key, use functions like RSA\_size(3), DH\_size(3), and DSA\_size(3).
