---
name: "htonl"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/byteorder"
---

# htonl(3)

convert values between host and network byte order

Part of [byteorder(3)](/byteorder/3.md).

## NAME

**htonl**, **htons**, **ntohl**, **ntohs** – convert values between host and network byte order

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#include \<arpa/inet.h\>**

or

**#include \<netinet/in.h\>**

*uint32\_t*\

**htonl**(*uint32\_t hostlong*);

*uint16\_t*\

**htons**(*uint16\_t hostshort*);

*uint32\_t*\

**ntohl**(*uint32\_t netlong*);

*uint16\_t*\

**ntohs**(*uint16\_t netshort*);

## DESCRIPTION

These routines convert 16 and 32 bit quantities between network byte order and host byte order. On machines which have a byte order which is the same as the network order, routines are defined as null macros.

These routines are most often used in conjunction with Internet addresses and ports as returned by [gethostbyname(3)](/gethostbyname/3.md) and [getservent(3)](/getservent/3.md).

## SEE ALSO

[gethostbyname(3)](/gethostbyname/3.md), [getservent(3)](/getservent/3.md), [byteorder(9)](/byteorder/9.md)

## STANDARDS

The **byteorder** functions conform to IEEE Std 1003.1-2001 (“POSIX.1”).

## HISTORY

The **byteorder** functions appeared in 4.2BSD.

## BUGS

On the VAX bytes are handled backwards from most everyone else in the world. This is not expected to be fixed in the near future.
