Networking 101: IPs and Netmask

Long Nguyen
7 min readApr 4, 2020

--

My notes while learning about IPs and Netmask

I. IPs

What is the internet

  • Network of computers connected to each other
  • From a technical point of view, it is a design philosophy, architecture that is expressed in a set of protocols

What is a protocol

  • In this context, a well-defined set of rules and standards used to communicate or exchange information between computers

What is Internet Protocol — IP

  • This is the principle protocol used in internet communication
  • It is responsible for addressing, delivering and routing the requests. It defines the format of packets, encapsulating data into datagrams

What is an IP address

  • A numeric address for a computer in a network — this address needs to be unique in the network
  • In a private network, router will assign the IP to your computer, in a public network, it is assigned usually by ISP — internet service provider
  • Consists of 2 parts: Network address and Host address
  • There are 2 types: IPv4 and IPv6

What is IP version 4 — IPv4

  • A numeric address with 4 set of numbers (called octet) separated by dots
  • This can provide more than 4 billion unique addresses
Source

What is IP version 6 — IPv6

  • Similar to IPv4 but instead of 4 octets, there are 6.
  • Provide 340 undecillion (36 zeros) unique addresses
Source

What is classful addressing

  • Initially, IP addresses are grouped into different class — each class has a fixed number of bits
  • It is designed with a fixed-length prefix. The 3 fixed-length prefixes are 8, 16, 24
Data Communication and Networking book by Behrouz A. Forouzan

Class A

  • The network length is first 8 bits
  • The first bit out of 16 bits, which is fixed at 0, define the class. Hence, it only has 7 bits left for network identifier (2⁷ = 128 available networks in class A)
  • First octet will have values from 0 to 127

Class B

  • The network length is first 16 bits
  • The first 2 bits out of 16 bits, which are fixed at 10, define the class. Hence, it only has 14 bits left for network identifier (2¹⁴ = 16k available networks in class B)
  • First octet will have values from 128 to 191

Class C

  • The network length is first 24 bits
  • The first 3 bits out of 24 bits, which are fixed at 110, define the class. Hence, it only has 21 bits for network identifier (2²¹ = 2 mil available networks in class C)
  • First octet will have values from 192 to 223

We won’t discuss class D and class E here for simplicity’s sake.

What is address depletion

  • This is the problem of classful addressing
  • The classful addressing makes the addresses distribute unevenly
  • Most of the addresses in class A, B are unused — most organisations don’t need 16k addresses in their networks
  • Meanwhile, class C usually does not have enough addresses in the network (256 addresses)

What is classless addressing

  • The whole address space (4 billions) is divided into variable length blocks
  • The prefix defines the block (network), suffix defines nodes (devices) — the prefix is variable
  • Small prefix means a larger network, large prefix means a smaller network
  • The idea of classless addressing can be applied to classful addressing — e.g: class A can be thought of classless address whose prefix length is 8
  • An address cannot define a block that it belongs to — it could belong to many blocks as long as it is within the range of those blocks
Data Communication and Networking book by Behrouz A. Forouzan

II. Networking

What is CIDR

  • A set of IP standards that are used to create unique identifiers for networks and individual devices — more flexible allocation of IPs
  • They do it via CIDR notation

What is CIDR notation

  • The prefix length added to the right side of the IP address, separated by a forward slash /. Use this to determine the network address and which digits are fixed
  • For example: IP address 192.168.1.168 with subnet mask 255.255.255.0 is written as 192.168.1.168/24 in CIDR notation

What is network address or network identifier

  • It is the first address that comes with the /[number] with all host bits set to 0
  • It’s super important because it is used in routing to its destination — when a router receives a packet, it needs to know which NETWORK it should send the packet to

3 important things that could be calculated from network address

  • Number of IP addresses in this network = 2^ (32 — n) with n = prefix
  • First address in the network range: keep first n digits (in binary) and set the rest to 0 (network id)
  • Last address in the network range: keep first n digits and set the rest to 1 (broadcast address)
Source

What is a subnetwork — subnet

  • A subdivision of a network (smaller network inside the network)
  • A range of addresses can be divided into several subranges and assign each sub range to a subnetwork (subnet)
  • We do this to create separate areas that don’t interfere with each other
  • Note that sub network can still be divided into sub-subnetworks
  • This allows more host computers to connect to the network without getting more IPs
  • Also allows router to deliver data to correct group of IPs (or subnet) — because in a network there could be many IPs, breaking it down to subnetworks would make it easier to find and deliver packets

For example, you have been issued this network block 10.10.0.0/16

  • Let’s divide this into 4 subnets — meaning you need to borrow 2 bits of your host address to form the subnet (00, 01, 10, 11) hence extending the net mask
  • 10.10.0.0/18 (first case, 2 bits 00, hence for this network the prefix is 18)
  • 10.10.64.0/18 (second case, 2 bits 01)
  • 10.10.128.0/18 (third case 2 bits 10)
  • 10.10.192.0/19 (fourth case 2 bits 11)
  • Subnet mask for these subnets is 255.255.192.0 (because to make subnet, set all prefix bits to 1, meaning set first 18 bits to 1)

How to create a subnet

We extend the given mask with some of the bits from the host ID portion (Steal bits from the host part of the IP address in order to divide the larger network into subnets). After this, we end up with network subnet host fields

We always reserve 2 IPs for each network. This means if we create subnets, the subnets also reserve 2 IPs for themselves

  • One to identify the subnet. Subnet identifier or address is defined by all 0 bits in the host part, which is the first IP in the subnet range
  • One for the broadcast subnet. This is defined by all 1s bits in the host part, which is the last IP in the subnet range

What is a net mask or subnet mask

  • It is a number defining the number of usable IPs inside the subnet (minus 1 for broadcast address and minus 1 for the subnet identifier) — or the number of computers that can talk directly to each other inside this subnet
  • The mask will tell you which byte is fixed and cannot change, and which one can be used for host and only reveal the network address part
  • Looking at the CIDR notation, you can identify the subnet mask

For example:

  • 192.168.1.0/24 => subnet mask can be found by setting 1 to the first 24 bits
  • Subnet mask: 255.255.255.0

What is broadcast address

Again, this is the address where all host bits are 1 is the subnet’s broadcast address — the biggest IP in a subnet/net

It cannot be assigned to any device since it is used to send messages to all devices in the subnet

Steps to find the broadcast address from the Net IP

  • Get the Net mask from Net IP (using the CIDR notation)
  • Bit complement of the Net mask (flip 1 to 0 and 0 to 1)
  • Get the net IP and do an OR with the bit complement

What are the differences between public IP and private IP

  • Public IP is the address assigned to a computing device to allow direct access over the internet — must be globally unique
  • Private IP is the address assigned to local devices inside a private network by router — they are not reachable directly from the internet, we have to go through router’s public IP — and they are not globally unique
Source
  • There are 3 address ranges reserved for private network
Source

III. References

What is an IP address

IP addresses and DNS

What happens when you type an url in the browser and press enter

IP Basics

What is the difference between a subnet mask and a net mask

IPv4 Addressing Lesson 2

How to find the broad cast address

How to organise your network into smaller subnets

Subnetting subnet masks explained

Public IP and Private IP and Port Forwarding

Until next time. Happy reading!

--

--