
Learn Computer Science
Developing a more interesting World
"Computer science is no more about computers than astronomy is about telescopes."
Edsger Dijkstra
Free beginner - intermediate level computer science tutorials
IP addresses
Tutoring > Operating Systems and Networks > Network Concepts
An IP address is a number assigned to a device in a network. It has 2 roles:
-
Host identification.
-
Location addressing.

Subnet mask (mask)
A subnet mask is a 32 bit number that masks an IP address, and divides the IP address into network address and host address. a subnet mask is made by setting network bits to all "1"s and setting host bits to all "0"s.
Performing a bitwise logical AND operation on the IP address with the subnet mask produces the network address.
If we have an IP address:
192.111.48.37
and a mask:
255.255.0.148
the network address is:
192.111.0.4
The simple way to work this out is:
-
If the mask part is 255, copy the IP part.
-
If the mask part is 0, the network part will be 0.
-
Otherwise, perform a bitwise logical AND on the two numbers.
e.g. if the numbers are 37 and 148:
00100101
10010100 so the network address part is 00000100 or 4.

Private IP addresses

IPV4
IP addresses are binary numbers but so humans can easily use them, they are represented using a string of numbers.
IPV4 format is as follows:
0.0.0.0 to 255.255.255.255
As each part of the 32 bit number is an 8 bit octet, the above represents the possible range of IPV4 addresses. There are 4,294,967,296 unique addresses in this range. There are other constraints on the range such as the reservation of some addresses for private networks.

IPV6
As the number of available addresses ran out, a new format was introduced with 128 bits (16 octets). This allowed for 2^128 unique addresses. A lot.
IPv6 addresses are represented as eight groups of four hexadecimal digits separated by colons, for example: 2001:0db8:85a3:0042:1000:8a2e:0370:7334, but methods of abbreviation of this full notation exist.
Devices not connected to the Internet need not have unique IP addresses.
Here are the ranges of addresses reserved for private use:
-
10.0.0.0 - 10.255.255.255 number of addresses : 16,777,216
-
172.16.0.0 - 172.31.255.255 number of addresses : 1048576
-
192.168.0.0 - 192.168.255.255 number of addresses : 65,536