Thursday 9 June 2022

Internet Protocol (IP) Addresses and Ranges

Internet Protocol (IP) is one of protocols from Network Layer.

Each node in IP network has IP address assigned so IP packets can be routed between them. 

IPv4 Addresses

image source:

  • IPv4 - Internet Protocol v4 (1981)
  • each node has its identifier - IP address  
  • 32-bit number divided in octets
    • example:
  • dot-decimal notation
  • four octets, four sections of 8 bits
  • each octet (each section) is 8-bit number so in total 32-bits required to represent the full addres; there are 2^32 combinations in total
  • to 
  • some addresses and ranges are reserved for e.g. private networks 

IPv6 Addresses

image source:

  • Introduced in order to expand the range of IP addresses.
  • 128-bit address scheme 
    • 2^128 (undecillion) address combinations 
  • IPv6 as hexadecimal: 8 segments of 16 bits separated by colons
    • Example: 1e03:b32f:042d:0000:0000:0000:0436:4aef
  • How to shorten IPv6 address:
    • Leading zeros in each segment can be omitted.
    • Segments with all zeros can be replaced with single zero:
      • 1e03:b32f:42d:0:0:0:436:4aef
    • Furthermore, a single subset of consecutive zeros can be replaced with two colons: 
      • 1e03:b32f:42d::436:4aef
      • This can be done only once as if we had two occurrences of double-colons we wouldn't know how many zeros each represent. 

Classless Inter-Domain Routing (CIDR) Notation

  • A way of specifying a range of IP addresses, including the case of a single IP address. 
    • Example:
  • Number after slash denotes leading bits in a 32-bit number that get frozen. In this example, 192.10 (first two octets) stays the same and the rest two octets change so we get the range from to Two last octets are free to change which gives us 2^16 addresses in this range.
  • Examples:
    • gives the range to
    • gives the single IP address:  
    • gives two IP addresses: and
    • gives four IP addresses: to 
    • freezes first 17 bits which is first 2 octets and first bit of 3rd octet so we get the range to (0111111 = 127)
    • freezes first 3 octets and first half (first 4 bits) of the 4th octet giving the range of 16 IP addresses: to (00001111 = 15)
  • AWS VPC allows leading bits between 16 (/16) and 28 (/28).

Private Network Ranges

  • Public IP range is routable to the Internet. These IP addresses can directly communicate to Internet. 
  • Private network ranges solve the problem of not having enough of IPv4 addresses for all devices connected to Internet.
  • Private Network Ranges (IETF specification RFC1918):
    • => to (~16 million addresses)
    • => to (~1 million addresses)
    • => to (~65k addresses)
  • Private IP range is not routable to the Internet, they are not publicly available, can be used only in private networks. Devices with private network IPs can reach Internet via Network Address Translation or proxy service - something that translates private IP address to public IP address. 


ipcalc Tool

ipcalc is a useful tool which visualizes subnet calculations.
To install it on Ubuntu Linux:
$ sudo apt install ipcalc
To visualize CIDR:

$ ipcalc
Address:          11000000.10101000.00000000. 00000000
Netmask: = 24   11111111.11111111.11111111. 00000000
Wildcard:            00000000.00000000.00000000. 11111111
Network:       11000000.10101000.00000000. 00000000
HostMin:          11000000.10101000.00000000. 00000001
HostMax:        11000000.10101000.00000000. 11111110
Broadcast:        11000000.10101000.00000000. 11111111
Hosts/Net: 254                   Class C, Private Internet


No comments: