xkonekt
Language: EN
  • English
  • Türkçe
  • Español, Coming soon
  • Português, Coming soon
  • Deutsch, Coming soon
  • Français, Coming soon

IPv4 addressing · Introduction · Module 1

IPv4 addresses: how the mask splits network and host

Show topologyHide topology
R2provider routerH1hostR1office routerSW1switchR3routerR4router192.168.1.0/24203.0.113.0/2410.0.34.0/24172.16.0.0/16

Interfaces and addresses · Et = Ethernet; .1 = the end of the address after the network in the first column (.1 on 192.168.1.0/24 is 192.168.1.1)

  • 192.168.1.0/24R1 Et0/0 .1H1 eth0 .10
  • 203.0.113.0/24R1 Et0/1 .2R2 Et0/0 .1
  • 172.16.0.0/16 through SW1R1 Et0/2 .1.1R3 Et0/0 .2.3R4 Et0/0 .3.4
  • 10.0.34.0/24R3 Et0/1 .3R4 Et0/1 .4
Topology · R1 joins three networks: H1’s office network, the provider link to R2, and the network R1 shares with R3 and R4.

At the top: R2, the provider router. Under it, R1, the office router, joined to R2 by a cable labeled 203.0.113.0/24. Left of R1 and a little higher: H1, a host, joined to R1 by a slanted cable from under its laptop icon, labeled 192.168.1.0/24. Under R1: the switch SW1, joined to R1 by a cable labeled 172.16.0.0/16. Under SW1, R3 at the left and R4 at the right, each a router with one cable to SW1, and a cable between them labeled 10.0.34.0/24.

What an IPv4 address is

Four octets, one interface

H1’s address is 192.168.1.10. Why four numbers, and why none above 255?

H1’s address is really 32 binary digits, each a 0 or a 1, and so many in a row are hard to read. A binary digit is a bit. The 32 bits are written in four groups of 8, and each group is an octet. Eight bits can count no higher than 255.

Each octet is written as an ordinary decimal number, with a dot before the next one, a way of writing called dotted decimal.

An IPv4 address, then, is a 32-bit number, and it is given to an interface of a device on a network. The address belongs to the interface, not to the whole device. Engineers also use the word “network” for one part of a network, the devices joined to each other with no router between them. R1 joins three such networks and has an interface in each, so it has three addresses, 192.168.1.1, 203.0.113.2 and 172.16.1.1.

In 192.168.1.10 the last octet, 10, is written with two digits, yet it is 8 bits like the other three (Figure 1.1).

Each bit of an octet has a place value, from left to right 128, 64, 32, 16, 8, 4, 2 and 1, and the octet’s number is the sum of the place values of its 1 bits. In 00001010 the 1 bits sit at 8 and 2, so the octet is 8 + 2 = 10. All eight bits at 0 give 0, and all eight at 1 give 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255.

192168110...8 bits8 bits8 bits8 bits0000101012864321684218 + 2 = 10
Figure 1.1 · H1’s address is four octets of 8 bits, and its last octet, 10, is 00001010.

Four boxes in a row hold 192, 168, 1 and 10, with a dot between each pair; under each box, “8 bits”. A line runs from the last box down to a framed row of 8 cells holding 0 0 0 0 1 0 1 0, with the two 1 cells highlighted. Under the cells are their place values, 128, 64, 32, 16, 8, 4, 2 and 1, with 8 and 2 highlighted, and at the foot the sum 8 + 2 = 10.

R1 has the address 172.16.1.1. How many bits does that address hold?

If you see 192.168.1.300, it looks like an address, but 300 needs more than 8 bits, so it is not one.

Key idea

An IPv4 address is 32 bits, written as four octets from 0 to 255. It names one interface.

How it works

The mask splits network from host

Network part and host part

An address names a network and one interface in it at once. Where does the network part end and the rest begin?

R1’s 192.168.1.1 and H1’s 192.168.1.10 share their first three octets. Those octets name the network and are the same for every device in it. They are the network part.

The remaining bits name the interface and differ for each one. They are the host part. Where the network part ends and the host part begins is not fixed. It is set on each interface.

How is it set? With a mask, a second 32-bit number beside the address. Its ones sit over the network part, and its zeros over the host part.

A mask only marks where the network part ends. It is written like an address, as four numbers with dots, but it names no device and no network.

In dotted decimal, an octet of all ones is 255 and an octet of all zeros is 0, so 255.255.255.0 is 24 ones, then 8 zeros. Under it, the first three octets are the network part and the last one is the host part.

A shorter way to write a mask is the number of ones in it, its prefix length. It is written after the address with a slash, as in 192.168.1.10/24. /24 and 255.255.255.0 are the same mask.

Masks that end where an octet ends
Prefix lengthMaskNetwork part
/8255.0.0.0first octet
/16255.255.0.0first two octets
/24255.255.255.0first three octets

Every mask in this topology is /16 or /24, and both end where an octet ends.

A longer prefix length leaves fewer host-part bits, 8 under /24 and 16 under /16, and so room for fewer devices.

Step through Figure 1.2 to find the address of H1’s network, its network address.

Step 1 of 7

H1192168110masknetworkR1

H1’s address is four octets, 192.168.1.10. Nothing in the address itself says where its network part ends.

Step 2 of 7

H119216811000001010masknetworkR1

In bits, the last octet, 10, is 00001010. The mask marks bits, not decimal numbers.

Step 3 of 7

H119216811000001010mask255255255024 ones · 8 zerosnetworkR1

H1’s mask is 255.255.255.0. In bits, that is 24 ones, then 8 zeros.

Step 4 of 7

H119216811000001010mask255255255024 ones · 8 zerosnetwork parthost partnetworkR1

The ones cover 192.168.1, the network part, and the zeros cover 10, the host part.

Step 5 of 7

H1192168110/2400001010mask255255255024 ones · 8 zerosnetwork parthost partnetworkR1

The mask has 24 ones, so H1’s address and mask are written short as 192.168.1.10/24.

Next, keep the network part and set the host part to zero. Which address is left?

  • 192.168.1.10: That is H1’s own address, with its host part, 10, still in place.
  • 192.168.1.0 (Correct): The mask’s ones cover 192.168.1, so that part stays. The host part is the last octet, 10, and it becomes 0.
  • 192.168.0.0: That zeroes the third octet as well. Under three 255s the third octet, 1, belongs to the network part.
  • 255.255.255.0: That is the mask itself. The answer has to come from H1’s address.

Step 6 of 7

H1192168110/2400001010mask255255255024 ones · 8 zerosnetwork parthost partnetwork19216810R1

With the host part set to 0, 192.168.1.0 is left, the address of the network itself, not of a device.

Step 7 of 7

H1192168110/2400001010mask255255255024 ones · 8 zerosnetwork parthost partnetwork19216810same network partR119216811/24

R1’s address toward H1 is 192.168.1.1/24. Under the same mask it has the same network part, 192.168.1, so R1 and H1 are in one network.

Step 1 of 7

Rows of four boxes, one box per octet, with the octets of every row in the same columns. Row “H1”: 192, 168, 1, 10, then /24. Under the last box a tag reads “00001010”. Row “mask”: 255, 255, 255, 0, with a tag “24 ones · 8 zeros”. A bar over the first three columns reads “network part”; a bar over the last column reads “host part”. Row “network”: 192, 168, 1, 0. Last, a bar over the first three columns reads “same network part”, and under it the row “R1”: 192, 168, 1, 1, then /24.

Figure 1.2 · The mask’s ones cover the network part of H1’s address, and its zeros the host part.H1’s address is four octets, 192.168.1.10. Nothing in the address itself says where its network part ends.In bits, the last octet, 10, is 00001010. The mask marks bits, not decimal numbers.H1’s mask is 255.255.255.0. In bits, that is 24 ones, then 8 zeros.The ones cover 192.168.1, the network part, and the zeros cover 10, the host part.The mask has 24 ones, so H1’s address and mask are written short as 192.168.1.10/24.With the host part set to 0, 192.168.1.0 is left, the address of the network itself, not of a device.R1’s address toward H1 is 192.168.1.1/24. Under the same mask it has the same network part, 192.168.1, so R1 and H1 are in one network.
Why does the address of H1’s network, 192.168.1.0, end in 0?

Same network or not

R1 joins three networks. Which devices share a network with R1, and how can you tell?

R1’s 172.16.1.1 and R3’s 172.16.2.3 differ in their third octet. Are they in one network? They are if the bits under the mask match, the same network part under the same mask. A device sends packets for an address in its own network directly across that network. For any other address it hands them to a router, a device that passes packets from one network to another.

SW1, a switch, joins the cables of R1, R3 and R4 into one network. The three routers’ addresses are 172.16.1.1/16, 172.16.2.3/16 and 172.16.3.4/16 (Figure 1.3).

R1office routerSW1switchR3routerR4router172.16.1.1/16172.16.2.3/16172.16.3.4/16
Figure 1.3 · R1, R3 and R4 share the network part 172.16 under the same /16 mask, so they are in one network.

R1, the office router, at the top, with a cable down to the switch SW1. Under SW1, R3 at the left and R4 at the right, each a router with one cable up to SW1. Each router’s address is written next to it: R1’s, 172.16.1.1/16, beside its icon, under “office router”, and R3’s and R4’s, 172.16.2.3/16 and 172.16.3.4/16, under their icons. In all three, the network part 172.16 is highlighted.

Under /16 the network part is the first two octets, 172.16, the same on all three. Under this mask the third octet belongs to the host part, so 172.16.1.1 and 172.16.2.3 are in one network.

So when you compare two addresses, read the mask first. Under /24 a different third octet would mean a different network, because there the third octet is network part.

192.168.1.0 looks like a device’s address, but its all-zero host part makes it the name of H1’s network, its network address, so no device is given it.

R1 keeps each interface’s address and mask in the settings it runs with, so you can read them on R1 itself. The command show running-config lists them, and | section interface Ethernet0/0 keeps only the part for Ethernet0/0, R1’s interface toward H1.

Output · IOS XE 17.18.2
R1#show running-config | section interface Ethernet0/0interface Ethernet0/01 ip address 192.168.1.1 255.255.255.0
  1. The address 192.168.1.1, then the mask 255.255.255.0. The mask has three 255s, so the network part is 192.168.1.

show ip interface Ethernet0/0 reports the same interface, and | include Internet address keeps only its address line, with the mask as a prefix length.

Output · IOS XE 17.18.2
R1#show ip interface Ethernet0/0 | include Internet address1  Internet address is 192.168.1.1/24
  1. The address, then its prefix length, /24, which is 24 ones.

Key idea

Two addresses are in one network when they have the same network part under the same mask.

Use the rule: keep the network part, set the host part to zero.

R4’s address is 172.16.3.4/16. Its network part is 172.16. What is its network address?

Verify

Read R1’s addresses and masks

One command prints R1’s three addresses without their interfaces. How do you tell which line is which network?

Read each line’s mask first, then its network part. The command is show running-config | include ip address, which keeps the lines of R1’s settings that contain “ip address”, most of them an address and its mask. On R1, the interface without an address shows no ip address.

Three of R1’s four interfaces carry an address, each in its own network (Figure 1.4). With the fourth, the list has four lines, one per interface.

R2provider routerH1hostR1office routerSW1switchEt0/0192.168.1.1/24Et0/1203.0.113.2/24Et0/2172.16.1.1/16Et0/3: no address
Figure 1.4 · R1’s three addresses sit in three different networks, and Et0/3 has no address.

R1, the office router, with R2 above it, H1 to its left and a little higher, and the switch SW1 under it. At R1’s end of each cable, the interface name on one side of the cable and its address on the other: Et0/0 and 192.168.1.1/24 on the cable to H1; Et0/1 and 203.0.113.2/24 on the cable to R2; Et0/2 and 172.16.1.1/16 on the cable to SW1. Under R1’s name and role, a third line reads “Et0/3: no address”; that interface has no cable.

All three networks work as planned.

Tap a line, or “Not in the output”, then submit.

Find the line of R1’s interface in the network it shares with R3 and R4.

Output · IOS XE 17.18.2
R1#show running-config | include ip address
  1. Three 255s, so the network part is 192.168.1, H1’s network.
  2. Three 255s, so the network part is 203.0.113.
  3. Two 255s, so the network part is 172.16, shared with R3 and R4.
  4. The fourth interface has no address.

For its interface toward SW1, Ethernet0/2, R1 also reports the interface’s address, with the mask as a prefix length.

Output · IOS XE 17.18.2
R1#show ip interface Ethernet0/2 | include Internet address1  Internet address is 172.16.1.1/16
  1. Address 172.16.1.1, prefix length /16, two octets of ones as in 255.255.0.0.

Key idea

Each ip address line gives one interface’s address and mask. In these masks, the number of 255s is the number of octets in the network part.

R1’s line ip address 203.0.113.2 255.255.255.0 belongs to one of its interfaces. Which device shares that network with R1?

Troubleshoot

When one end’s address or mask is wrong

R1 and R3 share a network. What does R1 see when R3’s address or mask is typed wrong?

To test whether another device answers, R1 sends it five test packets with ping. Each ! you see is a reply, and each . a packet that got none in time.

First, R1 tests R3 while both ends are set as planned.

Output · IOS XE 17.18.2
R1#ping 172.16.2.3Type escape sequence to abort.1Sending 5, 100-byte ICMP Echos to 172.16.2.3, timeout is 2 seconds:2!!!!!3Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
  1. Five test packets to 172.16.2.3, and R1 waits up to 2 seconds for each reply.
  2. Five exclamation marks, so R3 answered all five tests.
  3. Success rate is 100 percent, the share of tests answered.

Case 1 of 2.R1’s test of R3 gets no answer

  1. Case 1 · Symptom

    R1 prints five dots when it tests R3.

    Output · IOS XE 17.18.2
    R1#ping 172.16.2.3Type escape sequence to abort.Sending 5, 100-byte ICMP Echos to 172.16.2.3, timeout is 2 seconds:1.....2Success rate is 0 percent (0/5)
    1. Five dots.
    2. Success rate is 0 percent, so none of the five came back.
  2. Case 1 · Command

    Is R3 still in 172.16.0.0/16? Read R3’s own address lines.

  3. Case 1 · Output

    Output · IOS XE 17.18.2
    R3#show running-config | include ip address1 ip address 172.17.2.3 255.255.0.02 ip address 10.0.34.3 255.255.255.0 no ip address no ip address
    1. Key line R3’s network part is 172.17, not 172.16, so R3’s interface toward SW1 is in another network now.
    2. The address toward R4 on their own link is unchanged.
  4. Case 1 · How far it reaches

    R1 tests R4, another router in 172.16.0.0/16, to see whether only R3 is affected.

    Output · IOS XE 17.18.2
    R1#ping 172.16.3.4Type escape sequence to abort.Sending 5, 100-byte ICMP Echos to 172.16.3.4, timeout is 2 seconds:!!!!!1Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
    1. Success rate is 100 percent, so R4 answers.
  5. Case 1 · What it means

    R1SW1R3R4172.16.1.1/16no answer172.16.3.4/16172.17.2.3/16
    Figure 1.5 · Case 1 · R3’s address starts with 172.17, outside 172.16.0.0/16, so R1’s test gets no answer.

    R1 at the top, SW1 under it, R3 and R4 under SW1, the addresses of R3 and R4 written under the two routers and R1’s beside its icon, under its name. R3’s address reads 172.17.2.3/16, with 172.17 highlighted, and beside the cable from SW1 to R3 is a cross labeled “no answer”. R4 reads 172.16.3.4/16, and its cable has no cross.

    • Even with the right mask, 255.255.0.0, a network part of 172.17 puts R3’s address outside 172.16.0.0/16.
    • R3 no longer has 172.16.2.3, so no device answers R1’s test of that address.
    • R4 still answers, so R1 and SW1 work and the problem is on R3’s side.
  6. Case 1 · Fix

    Give R3 the address of the plan, 172.16.2.3 with the mask 255.255.0.0.

    Output · IOS XE 17.18.2
    R3#configure terminalEnter configuration commands, one per line.  End with CNTL/Z.1R3(config)#interface Ethernet0/02R3(config-if)#ip address 172.16.2.3 255.255.0.0R3(config-if)#end
    1. Picks R3’s interface toward SW1.
    2. The address and the mask of the plan.

    Impact Changing an interface’s address stops the traffic that still uses the old address.

  7. Case 1 · Proof

    R1 tests R3 again.

    Output · IOS XE 17.18.2
    R1#ping 172.16.2.3Type escape sequence to abort.Sending 5, 100-byte ICMP Echos to 172.16.2.3, timeout is 2 seconds:!!!!!1Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
    1. Success rate is 100 percent, so R3 answers again.

End of case 1. Solved: R3 is back in 172.16.0.0/16.

Case 2 of 2.R1’s test of R3 fails while R3’s address looks right

  1. Case 2 · Symptom

    None of R1’s five tests of R3 is answered.

    Output · IOS XE 17.18.2
    R1#ping 172.16.2.3Type escape sequence to abort.Sending 5, 100-byte ICMP Echos to 172.16.2.3, timeout is 2 seconds:1.....2Success rate is 0 percent (0/5)
    1. Five dots.
    2. Success rate is 0 percent, so none of the five came back.
  2. Case 2 · Command

    Read R3’s address lines, mask included.

  3. Case 2 · Output

    Output · IOS XE 17.18.2
    R3#show running-config | include ip address1 ip address 172.16.2.3 255.255.255.0 ip address 10.0.34.3 255.255.255.0 no ip address no ip address
    1. Key line The address is right, but the mask is 255.255.255.0, a /24. R1’s mask on SW1’s network is 255.255.0.0.
  4. Case 2 · How far it reaches

    R1 tests R4, the other router on SW1.

    Output · IOS XE 17.18.2
    R1#ping 172.16.3.4Type escape sequence to abort.Sending 5, 100-byte ICMP Echos to 172.16.3.4, timeout is 2 seconds:!!!!!1Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
    1. Success rate is 100 percent, so R4 answers.
  5. Case 2 · What it means

    R1SW1R3R4172.16.1.1/16no answer172.16.3.4/16172.16.2.3/24R3’s view: 172.16.2.0/24
    Figure 1.6 · Case 2 · R3’s /24 mask puts R1 outside R3’s network, so no answer comes back to R1.

    R1 at the top, SW1 under it, R3 and R4 under SW1, the addresses of R3 and R4 written under the two routers and R1’s beside its icon, under its name. R3’s address reads 172.16.2.3 with /24 highlighted, and a note under it reads “R3’s view: 172.16.2.0/24”. Beside the cable from SW1 to R3 is a cross labeled “no answer”. R4 reads 172.16.3.4/16, and its cable has no cross.

    • With 255.255.255.0, R3’s network part is the first three octets, so R3 takes its network to be 172.16.2.0/24.
    • For R3, R1’s 172.16.1.1 is outside that network, because the bits under the mask do not match. No answer comes back to R1.
    • R4 still answers, so the problem is on R3’s side. R3’s address is right, so only its mask needs changing.
  6. Case 2 · Fix

    The fix keeps R3’s address toward SW1 and gives that interface the mask of the plan, 255.255.0.0.

    Output · IOS XE 17.18.2
    R3#configure terminalEnter configuration commands, one per line.  End with CNTL/Z.R3(config)#interface Ethernet0/01R3(config-if)#ip address 172.16.2.3 255.255.0.0R3(config-if)#end
    1. The same address with the mask of the plan.

    Impact Changing an interface’s mask can briefly interrupt the traffic on that interface.

  7. Case 2 · Proof

    R1 tests R3 again.

    Output · IOS XE 17.18.2
    R1#ping 172.16.2.3Type escape sequence to abort.Sending 5, 100-byte ICMP Echos to 172.16.2.3, timeout is 2 seconds:!!!!!1Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
    1. Success rate is 100 percent, so R3 answers again.

End of case 2. Solved: Both ends use /16 again.

Both cases

Key idea

Devices in one network need the same network part and the same mask.

R3 is set as planned, but R4’s address is typed 172.61.3.4 with the mask 255.255.0.0. R1 tests R3 and then R4. What does it see?

Check

Which of these is a valid IPv4 address?
R3’s address is 172.16.2.3 with the mask 255.255.0.0. What is its network address?

R3 is set as planned.

Tap a line, or “Not in the output”, then submit.

Find the line that puts R3 in the same network as R1’s 172.16.1.1/16.

Output · IOS XE 17.18.2
R3#show running-config | include ip address
Which of these addresses could be given to an interface in the network of the link between R3 and R4, 10.0.34.0/24?
R4’s address stays 172.16.3.4, but its mask is typed 255.255.255.0. What does R1’s test of 172.16.3.4 show, and what keeps working?

Summary

H1192168110/2400001010mask255255255024 ones · 8 zerosnetwork parthost partnetwork19216810same network partR119216811/24
Figure 1.2, recap · R1’s address toward H1 is 192.168.1.1/24. Under the same mask it has the same network part, 192.168.1, so R1 and H1 are in one network.

Rows of four boxes, one box per octet, with the octets of every row in the same columns. Row “H1”: 192, 168, 1, 10, then /24. Under the last box a tag reads “00001010”. Row “mask”: 255, 255, 255, 0, with a tag “24 ones · 8 zeros”. A bar over the first three columns reads “network part”; a bar over the last column reads “host part”. Row “network”: 192, 168, 1, 0. Last, a bar over the first three columns reads “same network part”, and under it the row “R1”: 192, 168, 1, 1, then /24.

  • An IPv4 address is 32 bits in four octets, each from 0 to 255.
  • The mask’s ones mark the network part and its zeros the host part, and the prefix length counts the ones.
  • The network address has every host-part bit 0. Devices with the same network part under the same mask are in one network.
  • On R1, show running-config | include ip address lists the address and mask of each interface that has one.
  • When R3’s network part or mask put R1 outside its network, R1’s tests of R3 failed, while R4, set as planned, kept answering.