This content originally appeared on DEV Community and was authored by Erin Borders
Let's say you want to create a virtual private cloud. You have a virtual network with an address prefix of 10.240.0.0/24
. This will amount to 254 IP addresses. But where did this number come from? To understand why this is, you have to understand how IP addresses, CIDR notation and subnets work.
Have you ever wondered why IP addresses look like X.X.X.X where the X's are some 3 digit or less number? For example, 123.1.2.34
might look like an IP address to you, but 12345.3.00000
definitely doesn't? If you look up "popular IP addresses," the results will follow this pattern, and that isn't coincidence.
IP addresses have 4 blocks, i.e. those numbers in between the dots. Each of these blocks can be any number from 0 to 255. This is due to how computers work. It's relatively common knowledge that computers use binary right? That series of 1010001111010100
that looks like gibberish? Well you can think of that as their language, with each 0 or 1 being a character, aka a bit, and each set of 8 characters being a word, aka a byte. Just like we communicate with words, computers communicate with bytes. The 0 to 255 range we mentioned with IP address blocks comes from the amount of combinations of 1's and 0's we could possibly get in a byte. That's 2 to the 8th power of possibilities, aka 256 possibilities. Because 0 is included, the range is 0 to 255 instead of 1 to 256 like you might expect.
(You might be wondering, but why 4 blocks specifically? Without diving too deep into it, when the Internet was first becoming a thing, no one could fathom that we'd ever surpass the amount of IP addresses a 4 block combination would give us - after all, that's millions of possibilities. But, of course, the internet exploded beyond anyone's imaginings and now we have new versions of IP addresses that include way more than 4 blocks to account for this growth.)
Anyways, all of this is to say that our IP address is 4 blocks of 8 bits - 32 bits in total. The IP address "prefix," i.e. the 10.240.0
is the beginning part that all of our IP addresses in this virtual network will have. We know this because of the subnet mask.
The /24
at the end is called a subnet mask and it uses CIDR notation to tell us how many bits are "set in stone" so to speak. The /24
is just a quicker way to say 255.255.255.0
, meaning that the 256 possibilities of each block, i.e. the first 24 bits, are occupied.
So from the subnet mask, we know that the 10.240.0
portion of our IP address is locked in and not changing. The last 8 bits, i.e. the last 0
block, however is fair game, and remember a full block is 256 possible combinations. So if you create a virtual network with an address prefix of 10.240.0.0/24
that means 10.240.0.57
, 10.240.0.131
and 10.240.196
will all be IP addresses that you can use in your virtual network among 251 others.
You might be wondering why I said 251 instead of 253 - we have 256 IP addresses in total and I listed 3 examples so that should leave 253 others, right? When creating virtual networks a few of the IP addresses will be reserved. For instance, if you're creating your own network, the first and last IP addresses in your range will be reserved as the network and broadcast ID's (so, in our case, 10.240.0.0
and 10.240.0.255
). However, some cloud providers will reserve additional IP addresses so it's important to read the fine print if using a service to create your virtual network.
Thank you for taking the time to read this article! If you found this article helpful, please consider leaving me a star on Github or consider endorsing me for relevant skills on LinkedIn.
This content originally appeared on DEV Community and was authored by Erin Borders
Erin Borders | Sciencx (2023-04-30T22:43:35+00:00) Networking: Understanding Subnetting. Retrieved from https://www.scien.cx/2023/04/30/networking-understanding-subnetting/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.