IP Technology Basics · Topic 1 of 5

IPv4 Header, Addresses and Subnetting

Learn the IPv4 header fields, address classes, private and special addresses, masks and subnetting math for the Huawei HCIA-Datacom H12-811 exam.

  • 6 min
In a nutshell
  • The IPv4 header is 20 bytes minimum, 60 maximum, and the Protocol field values are 1 ICMP, 6 TCP, 17 UDP and 89 OSPF.
  • TTL stops loops, and the header checksum covers only the header.
  • Class A is 1 to 126, B 128 to 191, C 192 to 223, D (multicast) 224 to 239.

What it is

The network layer moves packets from one network to another. Its main protocol is IPv4, helped by ICMP for error and test messages and by ARP, which finds the MAC address for a next hop IP address on Ethernet.

An IPv4 address is 32 bits, written as four decimal octets such as 192.168.1.10. A mask splits it into a network part and a host part. Subnetting borrows host bits to cut one network into several smaller ones.

Upper layer dataIPv4 header addedsource and destination IPRouting lookuplongest matchData link frameARP finds next hop MAC

How it works

The IPv4 header

The header is 20 bytes without options and up to 60 bytes with them.

FieldSizePurpose
Version4 bits4 for IPv4
Header Length4 bitsHeader size in 4 byte units, 5 means 20 bytes
Type of Service (DS field)8 bitsPriority marking (DSCP) for QoS
Total Length16 bitsHeader plus data, up to 65,535 bytes
Identification16 bitsSame value on every fragment of one packet
Flags3 bitsDF (do not fragment) and MF (more fragments)
Fragment Offset13 bitsPosition of the fragment, in 8 byte units
TTL8 bitsDecreased by 1 at each router, discarded at 0
Protocol8 bitsUpper layer protocol: 1 ICMP, 6 TCP, 17 UDP, 89 OSPF
Header Checksum16 bitsChecks the header only
Source and Destination Address32 bits eachSender and receiver

When a packet is larger than the outgoing link MTU (1500 bytes on Ethernet by default), it is fragmented unless DF is set. The receiving host reassembles the fragments using Identification, MF and Fragment Offset.

Address classes

ClassFirst octetDefault maskUse
A1 to 126255.0.0.0 (/8)Unicast
B128 to 191255.255.0.0 (/16)Unicast
C192 to 223255.255.255.0 (/24)Unicast
D224 to 239NoneMulticast
E240 to 255NoneReserved

In binary, class A starts with 0, B with 10, C with 110, D with 1110 and E with 1111. Today classless addressing (CIDR) is used, and the prefix length decides the network part.

Private and special addresses

RangeMeaning
10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16Private, not routed on the internet, need NAT
127.0.0.0/8Loopback, tests the local stack
169.254.0.0/16Link local, used when DHCP fails
0.0.0.0This host, or the default route as 0.0.0.0/0
255.255.255.255Limited broadcast, never forwarded by routers

In each network, the address with all host bits 0 is the network address and all host bits 1 is the broadcast address. Neither can be given to a host.

Subnetting math

With n host bits, a subnet has 2^n addresses and 2^n minus 2 usable host addresses. Borrowing m bits gives 2^m subnets.

PrefixMaskAddressesUsable hosts
/24255.255.255.0256254
/25255.255.255.128128126
/26255.255.255.1926462
/27255.255.255.2243230
/28255.255.255.2401614
/29255.255.255.24886
/30255.255.255.25242

The block size is 256 minus the interesting mask octet. With /26 the block size is 64, so subnets start at .0, .64, .128 and .192. VLSM uses different prefix lengths inside one network, such as /30 for router links and /24 for user LANs.

Host count neededHost bits n2 to the n minus 2Prefix lengthBlock size256 minus mask octetNetwork, hosts, broadcast

Setting an address on VRP

<Huawei> system-view
[Huawei] interface GigabitEthernet0/0/0
[Huawei-GigabitEthernet0/0/0] ip address 192.168.1.1 255.255.255.0

The mask can also be given as a length, as in ip address 192.168.1.1 24. Check it with display ip interface brief.

A worked example

A host has 172.16.45.200/27. The block size is 256 minus 224, which is 32. The multiples of 32 are 160 and 192, so the host is in subnet 172.16.45.192.

The broadcast is 172.16.45.223, and the usable hosts are 172.16.45.193 to 172.16.45.222. That gives 30 usable addresses.

How the exam asks about this

  • "Which field in the IPv4 header prevents packets from looping forever?" → TTL, decreased by 1 at each hop.
  • "How many usable host addresses does a /28 subnet provide?" → 14.
  • "Which address can be configured on a host interface: 10.1.1.63/26, 10.1.1.64/26 or 10.1.1.65/26?" → 10.1.1.65/26, because .63 is a broadcast and .64 is a network address.

What to remember for the exam

  • The IPv4 header is 20 bytes minimum, 60 maximum, and the Protocol field values are 1 ICMP, 6 TCP, 17 UDP and 89 OSPF.
  • TTL stops loops, and the header checksum covers only the header.
  • Class A is 1 to 126, B 128 to 191, C 192 to 223, D (multicast) 224 to 239.
  • Private ranges are 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16.
  • Usable hosts are 2^n minus 2, and a /30 gives 2 hosts for a router link.
Watch out

127.x.x.x is not class A unicast and cannot be assigned to an interface, even though its first octet looks like class A.

Common mistakes

Forgetting the two reserved addresses. A /27 has 32 addresses but only 30 hosts. The network and broadcast addresses are not usable.

Reading 172.16.0.0/12 as 172.16 only. The private class B block runs from 172.16.0.0 to 172.31.255.255. An address like 172.20.1.1 is private too.

Counting Fragment Offset in bytes. It is counted in 8 byte units. An offset of 185 means byte 1480 of the original data.

Check yourself

  • What is the broadcast address of 192.168.10.70/26?

    192.168.10.127, because the /26 block size is 64 and the host sits in the 192.168.10.64 subnet.

  • Which IPv4 header field tells the receiver that more fragments follow?

    The MF (more fragments) flag, set on every fragment except the last one.

  • Is 169.254.10.5 a valid address to use on the internet?

    No. It is a link local address that a host gives itself when it cannot get one from DHCP.

Topic 1 of 5 in IP Technology Basics

Test yourself on IP Technology Basics

The full Huawei HCIA-Datacom H12-811 question bank has 600 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Huawei. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.