An IP (Internet Protocol) address is a unique identifier for devices on a network. It helps in routing data packets between different devices on the internet.
IPv4: The most commonly used version, it has 32 bits (4 bytes) and can represent around 4.3 billion unique addresses.
IPv6: The newer version, it has 128 bits (16 bytes) and can represent around 3.4 x 10^38 unique addresses.
An IPv4 address is divided into 4 octets (bytes), each ranging from 0 to 255. Octets are separated by a dot (.) in an IP address.
192.168.1.1An IPv6 address is divided into 8 groups of 4 hexadecimal digits, separated by colons (:).
2001:0db8:85a3:0000:0000:8a2e:0370:7334Subnetting is the division of a network into smaller networks for better management and security.
IP addresses are categorized into five classes (A, B, C, D, E) based on their default network prefix length.
What is the maximum number of unique IP addresses that can be represented by an IPv4 address?
Here's a simple example of IP address subnetting:
192.168.1.0/24 (24 bits for network prefix)255.255.255.0192.168.1.1192.168.1.255256 - 2 = 254subnet = "192.168.1.0/24"
subnet_mask = "255.255.255.0"
network = subnet.split("/")[0]
prefix_length = int(subnet.split("/")[1])
mask = "".join(["1" for _ in range(prefix_length)] + ["0" for _ in range(32 - prefix_length)])
broadcast = f"{network}.{int(subnet_mask.split('.')[-1])}.255.255"
print(f"Network: {network}")
print(f"Subnet mask: {subnet_mask}")
print(f"First available IP address: {network}.1")
print(f"Broadcast IP address: {broadcast}")
print(f"Number of available IP addresses: {4 ** (32 - prefix_length) - 2}")
Output:
Network: 192.168.1.0
Subnet mask: 255.255.255.0
First available IP address: 192.168.1.1
Broadcast IP address: 192.168.1.255
Number of available IP addresses: 254
š” Pro Tip: You can use online subnet calculators to simplify subnetting. They provide an easy-to-use interface and can save you time.