Skip to main content

Building Blocks in JS

IP address

Each of us has an address. In India, this usually starts with the apartment number/house number, street name, locality, city, state, and country. Just like there is a physical address that defines our location, the internet is like a world of its own, virtually much bigger than our physical one(opinionated), and each device, router, or entity in this network is identified with an IP address ( Internet Protocol Address ). If you have ever changed the password of your router you might have hit the IP address like 192.168.0.1, that is the address of that router.

Definition: Internet Protocol (IP) addresses are a set of unique numbers for each device or network connected to the Internet.

The IP address is used to identify and communicate over the Internet and this address is usually provided by an Internet Service Provider - Also called an ISP.

ISP - a company that provides subscribers with access to the internet. Airtel, Jio are some of the Internet Service Providers in India, this could vary from country to country, note that, depending on where you are reading this blog from, you could have different ISPs.

Basics

Each device connected to the internet has a unique identifier, most devices today, including computers use a protocol called TCP/IP protocol as a standard to communicate, in the TCP/IP protocol the unique identifier is called the IP Address! There are two kinds of IP addresses IPv4 and IPv6.

To pretty much do anything on the internet we need IP addresses, just like we need an address to send mail to your friend or to receive mail, we need IP addresses to send or receive data on the internet. The YouTube videos you watch, the emails you send and receive, or simply using any website on the internet requires an IP address to send/receive data.

Types of IP Addresses

Consumer IP Addresses

All of us use both private and public addresses. A private address is used inside of a closed network, just like you might have a name inside of a group of friends, and we use the public IP Address to communicate with all of the outside networks. Both kinds of IP addresses are used by every individual that is connected to the internet.

Private IP Addresses

Private IP addresses are used within local networks and are not directly accessible from the internet. These addresses facilitate communication between devices within a private network, such as a home or corporate LAN, by providing a unique identifier for each device within that network. The use of private IP addresses helps conserve the limited pool of public IP addresses and enhances network security by keeping internal network traffic hidden from external entities. Private IP address ranges are defined by standards set in the Internet Engineering Task Force (IETF) and include specific blocks of addresses such as 192.168.x.x, 10.x.x.x, and 172.16.x.x to 172.31.x.x. Essentially, when you connect your devices to your router, it assigns private IP Addresses to those devices to identify them and send data packets to them.

Just like say a person named Rajesh could have a nickname of Raj and be used at home but to the rest of the world, he is not "Raj" but is identified as Rajesh, right?

Let's understand with another example, say there are 10 unique numbers which you need to share within 20 people but each one of them has to be indentified uniquely, not possible, right? This is exactly the case with roll numbers in a class. Say there are 40 students in 5th standard and 40 students in 6th standard, but you need to have the roll number start with 1, how do you do it? You know that the group is different, so the roll number 20 of 5th is actually 5th standard - roll number 20, and 6th standard roll number 20 is another person, just like that, imagine private networks like classrooms, and the IPs can be unique within that group but in some other part of the world within another private network, there could be the same private IP but since they connect to the external work via the public IP, it will never clash!

Public Addresses

Our public IP Address is the one that is given to us by the Internet Service provider. This is used to communicate with the rest of the internet. This is the address that the router uses to get what we say "Online". Similarly, other computers and devices use their public IP Addresses to communicate with other devices on the internet. Public IP addresses are unique numerical identifiers assigned to devices on the internet. They enable devices from different networks to communicate with each other by providing a global address that can be accessed from anywhere in the world. Public IP addresses are managed by organizations such as the Internet Assigned Numbers Authority (IANA) and are allocated by regional Internet registries to Internet Service Providers (ISPs), which then distribute them to end-users.

Imagine these like your Aadhar number, it is unique to you and it is unique across the world, this will never change in your life time. this is what is used to indentify you among the billions of people in the world, similarly, a public IP is unique and is used to identify that particular device/entity in the world of the internet.

IPv4 vs IPv6

In the IPv4, the IP Addresses are defined using 32-bit binary numbers. The complete address has four 8-bit binary numbers represented as a base-10 i.e. a decimal number (please refer to the Article on the Number system to understand more about what a decimal vs binary number is and how it works). The 8-bit numbers are also called as octets. The 4 sets of numbers make the IP address complete.

As we can see, 172, 16, 254, and 1 are represented in 8-bit binary, which is read as decimal which together makes the IP address, each 8-bit binary as the name says has "8 bits" which is 1 byte because 8 bits = 1 byte, since there are 4 sets of the 8-bit numbers, it makes 32 bits ( 8 X 4 = 32 ).

Unlike IPv4, IPv6 uses 128 bits to represent an IP Address. An IPv6 is represented as 8 groups of hexadecimal numbers (base-16), separated by colons.

2001:0db8:85a3:0000:0000:8a2e:0370:7334 is an IPv6 IP Address

  • 2001 (hex) = 0010 0000 0000 0001 (binary)
  • 0db8 (hex) = 0000 1101 1011 1000 (binary)
  • 85a3 (hex) = 1000 0101 1010 0011 (binary)
  • 0000 (hex) = 0000 0000 0000 0000 (binary)
  • 0000 (hex) = 0000 0000 0000 0000 (binary)
  • 8a2e (hex) = 1000 1010 0010 1110 (binary)
  • 0370 (hex) = 0000 0011 0111 0000 (binary)
  • 7334 (hex) = 0111 0011 0011 0100 (binary)

Static vs Dynamic

Static IP Addresses are like a permanent home address for a computer or device on the internet. Once you get a static IP address, it stays the same all the time, making it easy for other devices or websites to find and connect to your device consistently. For example, imagine your favorite video game server has a static IP address. Whenever you want to play, you use that address to connect to the server, and you always end up in the same game world with your friends because the address never changes.

Dynamic IP Addresses, on the other hand, are like temporary rental addresses. When you connect to the internet, your device gets a different address from a pool of available addresses, which can change each time you connect. For instance, when you use your home Wi-Fi, your router assigns a dynamic IP address to your computer or phone. The next time you connect, it might get a new address. This system is more flexible and efficient, allowing multiple devices to use the same network without needing a permanent address for each one.

A router has a public and a private IP address too. The public is the one it uses to talk to the rest of the internet. Also, the router has a certain number of private IP addresses, depending on the available one - based on if other devices have occupied it, our device will get one too.

Imagine a college classroom, we do not get a permanent seat right? Depending on who comes first, they occupy the seat of their choice. This is like the dynamic seat ( Dynamic IP Address ).

Conclusion

IP Addresses are one of the root and foundational concepts of the internet, understanding the internet is as important as learning a programming language. To become a mature programmer, understanding the fundamentals is critical, this is what will help you stand out in the crowd of millions of developers. Onward and forward!