Monday, 20 September 2021

How Computers Understand IPv4 Addresses

IPv4 in Different Formats
What Humans See vs What Computers See
Human Format (Dotted Decimal): 192.168.1.1
Computer Format (32-bit Binary): 11000000.10101000.00000001.00000001
Computer Format (Single Decimal): 3232235777

Step-by-Step Conversion Example
Let's take the IP address 192.168.1.1 and see how a computer processes it:
Step 1: Convert Each Octet to Binary
192 = 11000000
168 = 10101000
1   = 00000001
1   = 00000001

Step 2: How to Convert Decimal to Binary
Let's break down 192:
192 ÷ 2 = 96 remainder 0
96  ÷ 2 = 48 remainder 0
48  ÷ 2 = 24 remainder 0
24  ÷ 2 = 12 remainder 0
12  ÷ 2 = 6  remainder 0
6   ÷ 2 = 3  remainder 0
3   ÷ 2 = 1  remainder 1
1   ÷ 2 = 0  remainder 1
Reading upward: 11000000

Step 3: Computer's Internal Representation
The computer sees the entire IP as one 32-bit number:
11000000 10101000 00000001 00000001

Step 4: Converting to Single Decimal Number
To get the decimal equivalent:
Binary: 11000000101010000000000100000001
Decimal: 3,232,235,777

More Examples
Example 1: Google's DNS 8.8.8.8
Human: 8.8.8.8
Binary: 00001000.00001000.00001000.00001000
Single Decimal: 134,744,072
Conversion of 8 to binary:
8 ÷ 2 = 4 remainder 0
4 ÷ 2 = 2 remainder 0  
2 ÷ 2 = 1 remainder 0
1 ÷ 2 = 0 remainder 1
Result: 00001000

Example 2: Localhost 127.0.0.1
Human: 127.0.0.1
Binary: 01111111.00000000.00000000.00000001
Single Decimal: 2,130,706,433

###  Behind the Scenes: How Your Computer Uses This
Here's what happens when you type `ping 192.168.1.1`:
1. Parse: Computer splits "192.168.1.1" into [192, 168, 1, 1]
2. Convert: Each number becomes 8-bit binary
3. Combine: Creates the 32-bit address `11000000101010000000000100000001`
4. Process: Uses binary operations for routing decisions

### Network Calculations Made Simple
Your computer uses these binary representations for lightning-fast network calculations:
Your IP:       192.168.1.100 → 11000000.10101000.00000001.01100100
Subnet Mask:   255.255.255.0 → 11111111.11111111.11111111.00000000
Network:       192.168.1.0   → 11000000.10101000.00000001.00000000

This binary math helps your router instantly determine whether to send data locally or to the next hop on the internet.


No comments:

Post a Comment