Chapter 1: Networking Fundamentals
1.4 IPv4 in detail
Friends, pay attention. This is the most important section of the chapter, so focus completely. Once IPv4 is clear, CIDR and subnets in AWS will feel very natural. Don't worry – take a pen and paper and do the calculations with me.
मित्रांनो, लक्ष द्या. हा या चॅप्टरमधला सगळ्यात इम्पॉर्टंट सेक्शन आहे, म्हणून एकदम लक्ष द्या. IPv4 क्लिअर झालं की AWS मधले CIDR आणि सबनेट्स एकदम सोपे वाटतील. घाबरू नका – पेन आणि कागद घ्या, आणि माझ्यासोबत हिशोब करा.
दोस्तों, ध्यान दो. ये इस चैप्टर का सबसे इम्पॉर्टेंट सेक्शन है, इसलिए पूरा ध्यान दो. IPv4 क्लियर हो गया तो AWS में CIDR और सबनेट्स बिल्कुल आसान लगेंगे. घबराओ मत – पेन और कागज़ लो, और मेरे साथ हिसाब करो.
Structure
An IPv4 address is 32 bits, written as four octets (8 bits each) in dotted-decimal form. Each octet ranges from 0 to 255.
192 . 168 . 1 . 10
11000000 10101000 00000001 00001010
|<-8 bits->|
|<---------------- 32 bits ---------------->|
Total possible IPv4 addresses = 2^32 ≈ 4.3 billion — not enough for today's world of phones, laptops and IoT devices. That is the main reason for NAT, private IPs and IPv6.
Every IPv4 address has two parts:
- Network portion — identifies the network (like the street name).
- Host portion — identifies the device on that network (like the house number).
The subnet mask tells which bits are network and which are host. Example: 255.255.255.0 means the first 24 bits are network bits.
Classful addressing (historical but asked in exams)
| Class | First octet range | Leading bits | Default mask | Networks / Hosts per network | Use |
|---|---|---|---|---|---|
| A | 1 – 126 | 0 | 255.0.0.0 (/8) | 126 / ~16.7 million | Very large networks |
| B | 128 – 191 | 10 | 255.255.0.0 (/16) | 16,384 / 65,534 | Medium networks |
| C | 192 – 223 | 110 | 255.255.255.0 (/24) | ~2 million / 254 | Small networks |
| D | 224 – 239 | 1110 | — | — | Multicast |
| E | 240 – 255 | 1111 | — | — | Experimental / reserved |
What about 127?
127.0.0.0/8 is reserved for loopback. 127.0.0.1 (also called localhost) always means "this same machine". When an app listens on 127.0.0.1:3000, it is reachable only from the server itself — that is exactly what we want behind a reverse proxy.
CIDR (Classless Inter-Domain Routing)
Classes waste addresses (a company needing 500 hosts would get a whole Class B of 65,534). CIDR replaced classes. We write the address followed by /n, where n = number of network bits.
| CIDR | Subnet mask | Total addresses | Usable hosts (traditional) | Usable in AWS subnet |
|---|---|---|---|---|
| /16 | 255.255.0.0 | 65,536 | 65,534 | 65,531 |
| /20 | 255.255.240.0 | 4,096 | 4,094 | 4,091 |
| /24 | 255.255.255.0 | 256 | 254 | 251 |
| /25 | 255.255.255.128 | 128 | 126 | 123 |
| /26 | 255.255.255.192 | 64 | 62 | 59 |
| /27 | 255.255.255.224 | 32 | 30 | 27 |
| /28 | 255.255.255.240 | 16 | 14 | 11 |
| /32 | 255.255.255.255 | 1 | single host | — |
Formula: total addresses = 2^(32 − n), for an ordinary IPv4 subnet with a network address and a broadcast address, usable hosts = 2^(32 − n) − 2. A /31 point-to-point link can use both addresses, and /32 represents one address. AWS VPC subnet sizing follows the VPC rules below.
AWS reserves 5 addresses
In an ordinary AWS VPC IPv4 subnet, the first four and the last addresses are reserved. They include the network address and the VPC router. The VPC’s primary IPv4 range plus two is an Amazon-provided DNS address, and the third address stays reserved in each subnet. AWS also reserves the subnet’s last address. A typical /24 gives 251 assignable addresses. An individual IPv4 CIDR block for a regular VPC or subnet can range from /16 through /28. VPCs can also have additional eligible CIDR blocks.
0.0.0.0/0 means "every IPv4 address" — you will see it in security groups ("anywhere") and route tables (default route).
Suppose the Mauli Dairy office Wi-Fi network is 192.168.1.0/24 – that means the first 24 bits belong to the network and the last 8 bits to the devices, giving 254 usable hosts. If the same block were an AWS subnet, you would get 251 usable IPs, because AWS reserves 5 addresses in every subnet.
Mauli Dairy च्या ऑफिस Wi-Fi चं नेटवर्क 192.168.1.0/24 आहे असं समजा – म्हणजे पहिले 24 बिट्स नेटवर्कचे आणि शेवटचे 8 बिट्स डिव्हाइसेसचे, म्हणजे 254 usable होस्ट्स. तेच जर AWS सबनेट असतं तर 251 usable IPs मिळतील, कारण AWS प्रत्येक सबनेटमध्ये 5 ॲड्रेसेस राखून ठेवतो.
मान लो Mauli Dairy के ऑफ़िस Wi-Fi का नेटवर्क 192.168.1.0/24 है – मतलब पहले 24 बिट्स नेटवर्क के और आख़िरी 8 बिट्स डिवाइसेस के, यानी 254 usable होस्ट्स. वही अगर AWS सबनेट होता तो 251 usable IPs मिलेंगे, क्योंकि AWS हर सबनेट में 5 ऐड्रेसेस रिज़र्व रखता है.
Worked subnetting example
Come on, let's work through an example together now – take a pen and paper, don't just read.
चला, आता एक उदाहरण एकत्र करूया – पेन आणि कागद घ्या, फक्त वाचू नका.
चलो, अब एक उदाहरण साथ में करते हैं – पेन और कागज़ लो, सिर्फ़ पढ़ो मत.
Problem: Your college lab is given the network 192.168.10.0/24. Divide it into 4 equal subnets for four labs. Find each subnet's network address, usable range and broadcast address.
Step 1 — borrow bits. 4 subnets need 2 extra bits (2² = 4). New prefix = 24 + 2 = /26.
Step 2 — block size. Addresses per subnet = 2^(32−26) = 64. Mask = 255.255.255.192.
Step 3 — list subnets (increase the last octet in steps of 64):
| Subnet | Network address | First usable | Last usable | Broadcast | Usable hosts |
|---|---|---|---|---|---|
| Lab 1 | 192.168.10.0/26 | 192.168.10.1 | 192.168.10.62 | 192.168.10.63 | 62 |
| Lab 2 | 192.168.10.64/26 | 192.168.10.65 | 192.168.10.126 | 192.168.10.127 | 62 |
| Lab 3 | 192.168.10.128/26 | 192.168.10.129 | 192.168.10.190 | 192.168.10.191 | 62 |
| Lab 4 | 192.168.10.192/26 | 192.168.10.193 | 192.168.10.254 | 192.168.10.255 | 62 |
Step 4 — check with binary. Host 192.168.10.100: last octet 100 = 01100100. The first two bits (01) are the subnet bits → subnet 1 (counting from 0) → it belongs to Lab 2 (192.168.10.64/26).
Quick trick for block size
When the mask ends partway through an octet, subtract that partly filled octet from 256 to find the step in that octet. For /26 the mask is 255.255.255.192, so block = 256 − 192 = 64. Subnets start at 0, 64, 128, 192.
AWS example: A VPC 10.0.0.0/16 is commonly split into subnets 10.0.1.0/24 (public, AZ-a), 10.0.2.0/24 (public, AZ-b), 10.0.11.0/24 (private, AZ-a) and 10.0.12.0/24 (private, AZ-b).
You can check subnet maths on Linux with the ipcalc tool (package ipcalc):
ipcalc 192.168.10.64/26
Ravindra Bagale's Tip
Subnetting comes with practice, not with reading. For one week, solve five problems every day – using the block-size trick (256 − mask octet) – and check every answer with ipcalc. In interviews you are very often asked to split a /24 into four subnets on the whiteboard – you will be ready.
Ravindra Bagale's Tip – मराठी
Subnetting वाचून नाही, practice ने येतं. एक आठवडा रोज पाच problems सोडवा – block-size trick (256 − mask octet) वापरून – आणि प्रत्येक उत्तर ipcalc ने check करा. Interview मध्ये whiteboard वर /24 चे चार subnets करायला खूप वेळा विचारतात – तुम्ही तयार असाल.
Ravindra Bagale's Tip – हिंदी
Subnetting पढ़कर नहीं, practice से आता है. एक हफ़्ता रोज़ पाँच problems हल करो – block-size trick (256 − mask octet) इस्तेमाल करके – और हर जवाब ipcalc से check करो. Interview में whiteboard पर /24 के चार subnets बनाने को बहुत बार कहते हैं – आप तैयार रहोगे.
Ravindra Bagale's Tip
Many students say a /26 has 64 usable hosts. Wrong! 64 is the total number of addresses – subtract the network and broadcast addresses and you get 62, and in an AWS subnet 59. Remember the formula: 2^(32 − n), then −2 (−5 in AWS).
Ravindra Bagale's Tip – मराठी
बरेच students /26 मध्ये 64 usable hosts सांगतात. चूक! 64 हे total addresses आहेत – network आणि broadcast वजा केले की 62, आणि AWS subnet मध्ये 59. Formula लक्षात ठेवा: 2^(32 − n), मग −2 (AWS मध्ये −5).
Ravindra Bagale's Tip – हिंदी
बहुत से students /26 में 64 usable hosts बताते हैं. गलत! 64 total addresses हैं – network और broadcast घटाओ तो 62, और AWS subnet में 59. Formula याद रखो: 2^(32 − n), फिर −2 (AWS में −5).
Lab
Chala, 10.0.0.0/24 che 4 equal subnets kara: navin prefix, block size, pratyek subnet cha network address, usable range aani broadcast liha. Mag ipcalc 10.0.0.64/26 chalvun tumchya dusrya subnet che uttar match kara.
Got it? IPv4 = 32 bits, CIDR /n = network bits, and the block-size trick – once these three things are solid, subnetting will feel easy. Now let's move on to IPv6.
समजलं का? IPv4 = 32 बिट्स, CIDR /n = नेटवर्क बिट्स, आणि ब्लॉक-साइझ ट्रिक – या तीन गोष्टी पक्क्या झाल्या की सबनेटिंग सोपं वाटेल. आता पुढे जाऊया IPv6 कडे.
समझ आया? IPv4 = 32 बिट्स, CIDR /n = नेटवर्क बिट्स, और ब्लॉक-साइज़ ट्रिक – ये तीन चीज़ें पक्की हो गईं तो सबनेटिंग आसान लगेगा. अब आगे चलते हैं IPv6 की तरफ़.
Start with the address plan the dairy actually needs
Suppose Mauli Dairy is opening an ordering service with two web entry subnets and two private app subnets. The app will grow during festival orders. It will also reach a distribution office’s private network later. The first decision is a range of addresses that can accommodate that plan and still be recognized by the rest of the organization. If you choose the same block as the office, a later connection between them can become difficult because the same destination appears to belong to two places. If you choose a subnet with too few assignable addresses, the app might have no place to add a replacement server during its busiest day.
IPv4 subnetting solves a practical design problem. It gives a team a precise way to name a block of addresses, split it, and check which machines and routes belong to each part. It helps a router recognize a destination. It helps a cloud engineer see whether a subnet still has room. It helps a support engineer explain why a machine sent a request to a router instead of trying to find the other device over its local network. A correct plan makes each of those outcomes predictable.
In this lesson, use 10.50.0.0/16 for the dairy’s practice VPC and 10.60.0.0/16 for the distribution office. The two blocks are private and distinct. We will assign work areas inside the first block and then check two possible growth plans. These numbers are for your notebook. On a real account, check the ranges already approved by the team and verify all subnets before submitting them. The Linux and Python exercises below can run entirely offline.
Read four fields in each example: the network range, the part that can vary, the addresses reserved by the environment, and the purpose of the subnet. Each field answers a different question. An address can be mathematically inside a range and still be reserved. A perfectly aligned range can still overlap another network you need to connect. An eligible address assigned to a server still needs routes and permissions to reach other services. Keeping the fields separate helps you finish the design in the right order.
See what four decimal numbers represent
IPv4 has a 32-bit address. A bit holds one of two values. Grouping the bits into four groups of eight makes them easier for people to read. Each of those eight-bit groups is an octet. The leftmost bit in an octet contributes 128 when it is on, then the next contributes 64, then 32, 16, 8, 4, 2 and 1. Add the contributions that are on. For example, 01000110 gives 64 + 4 + 2 = 70. Eight zeros give 0. Eight ones give 255.
Take a last octet of 31. The bits for 16, 8, 4, 2 and 1 are on. Write that as 00011111. Now turn the 32 bit on as well. The value becomes 63 and the writing is 00111111. This is a useful base for understanding why a range can begin or end partway through an octet. A prefix can lock the leftmost few bits while leaving the remainder to vary. The dots are display separators, not fixed boundaries for every network.
Try the same idea at two different places. In 192.168.10.70, the last octet is 70. In 10.50.19.40, the third octet is 19, or 00010011. If a prefix includes the first four bits of that third octet, then the left side is 0001 and the lower four bits can vary. All third-octet numbers from 16 through 31 have that same pattern. The fourth octet may also vary. An engineer who sees this structure can calculate the surrounding block without treating every slash length as an isolated fact to memorize.
There are 2^32 possible IPv4 bit patterns. Some patterns have reserved roles, such as loopback, private use and documentation. A numerical count of patterns is therefore different from the number of assignable public interfaces. Likewise the size of a subnet is different from the number of addresses an ordinary host may use. Record both numbers in your calculations instead of saying “IPv4 has this many hosts” without context.
Read the slash number and subnet mask together
CIDR writes an address range as a starting address and a slash length. The slash tells how many leading bits are fixed in all of that range’s addresses. In a subnet mask the fixed positions are written as ones and the remaining positions as zeros. /24 has three octets of all ones and a final octet of zeros, so its mask is 255.255.255.0. /26 has two more ones in the last octet, 11000000, which is 192. Its mask is therefore 255.255.255.192.
Apply that mask to the example 192.168.10.70/26. The last octet of the address is 01000110. Keep the bits where the mask has ones and set the other bits to zero. The result in the last octet is 01000000, or 64. The network is 192.168.10.64/26. Put ones in the six varying positions to find the block’s last address. The last octet becomes 01111111, or 127. This calculation gives the network start and end without assuming the submitted address was already the network address.
There are six varying bits, so the total size is 2^6 = 64. For a typical office IPv4 subnet with a network and a broadcast address, the ordinary host address range is .65 through .126 in this example. Under the usual AWS VPC reservation rule the assignable addresses would be .68 through .126, giving 59. The bit arithmetic has stayed the same. The system’s reservations change what you can assign inside the block.
Notice what happened to the range as the slash grew. A bigger prefix length holds more bits fixed, so fewer addresses fit. A /25 leaves seven bits and holds 128 addresses. A /26 leaves six and holds 64. A /27 leaves five and holds 32. Say “more fixed bits, fewer assignable positions” when you compare choices. It is easier to remember the relationship than to learn every row of a table as a different rule.
Historical Class A, B and C sizing helps explain why old material speaks of /8, /16 and /24 as defaults. CIDR can express any valid prefix length for a network purpose. Modern equipment needs that explicit prefix to interpret the actual planned range. The first octet by itself does not determine which mask belongs to a particular cloud subnet. If an interview question asks for a number of hosts, say which prefix and reservation rule you are using.
Find an aligned start quickly when the prefix cuts an octet
For many paper exercises, you can count the block size in the octet where the mask changes from ones to zeros. Start with /20. Two octets are all ones and four bits of the third octet are fixed. Those four bits form 11110000, equal to 240. Subtract 240 from 256 to get a step size of 16 in the third octet. The boundaries in that octet are 0, 16, 32, 48, and so on. Every boundary also starts with 0 in the final octet because all the final-octet bits can vary.
Now plan the app network for the dairy. It has 10.50.0.0/16 available and wants a group for several internal tests. The suggested address is 10.50.35.19/20. A third octet of 35 falls between 32 and 47 because those are the values in the block starting at 32. The aligned network is 10.50.32.0/20. Its last address is 10.50.47.255. The next range starts at 10.50.48.0/20. If another engineer suggests 10.50.40.0/20 for a separate subnet, that suggestion lands inside the earlier block.
Make the arithmetic repeatable. Write the octet with the partial mask. Write the step. Find the largest aligned boundary at or below the octet’s value. Start all later host-only octets at zero for the first address. For the last address, use the next boundary minus one in the partial octet and use 255 for later octets. If the slash fully ends at an octet boundary, the split is already visible in the written groups. For example, 10.50.35.19/24 belongs to 10.50.35.0/24.
Here is a check for an octet students often overlook. 172.20.1.9 is inside 172.16.0.0/12. A /12 fixes the first octet and the first four bits of the second. The step in the second octet is 16. The block starting at 16 runs through 31, so it includes 20. 172.32.1.9 falls in the next block, outside the RFC 1918 range named above. An engineer can check a private range without treating the whole 172 first octet as private space.
When a cloud API accepts a CIDR typed with host bits, it can canonicalize the block to the aligned network form. Read the actual documented behavior of the create operation you use. For Terraform, CLI or a console exercise, submit the precise start you intend and then confirm the resource’s resulting CIDR. A tool that normalizes 10.50.35.19/20 to its network has not given you a new disjoint block. It has named the range that already contains those bits.
Count total addresses before applying the environment’s reservations
Take 10.50.8.0/28. The prefix fixes 28 of the 32 bits, leaving four varying bits and 16 addresses. The first one is 10.50.8.0, and the last is 10.50.8.15. In an ordinary AWS VPC IPv4 subnet the first four and the last address are reserved. In this range that means .0, .1, .2, .3, and .15. The remaining count is 11, and the example assignable set is .4 through .14. Always compute the last value before subtracting the reservation count.
The address just after the network address is reserved for the VPC router. AWS also reserves other early values for infrastructure and future use. In particular, the Amazon-provided DNS resolver has documented addresses, including the base address of the VPC’s primary IPv4 CIDR plus two. The address equal to each subnet’s base plus two is reserved even though it is not a separate resolver endpoint to use for every subnet. The last address is reserved in the AWS subnet model, although VPC networking does not support ordinary broadcast in that subnet. Keep the reservation arithmetic and the behavior of real services distinct.
| Planning example | Total IPv4 addresses | Ordinary AWS subnet after reservations | What this count is useful for |
|---|---|---|---|
/24 | 256 | 251 | Planning a lab with room for more workloads and interfaces. |
/26 | 64 | 59 | Planning a modest subnet after estimating growth. |
/27 | 32 | 27 | Checking service minimums and free-space headroom. |
/28 | 16 | 11 | Reasoning about an intentionally small practice range. |
An ordinary IPv4 LAN often reserves its network and broadcast addresses, which leads to the familiar subtraction of two. A /31 point-to-point link can use both addresses under its special rule. A /32 identifies one exact IPv4 address and is frequently useful in a source rule or a host route. The ordinary AWS subnet sizing and reservation model applies to the AWS subnet you are creating. A numerical tool can calculate a /31; the calculation alone does not mean AWS allows it as a normal IPv4 subnet CIDR. Read platform limits separately from mathematical possibilities.
Check what actually consumes the subnet. An interface can use one private address and may use additional addresses. Managed resources can also require free addresses for moving or scaling. In specific deployments an Application Load Balancer needs subnets that meet its minimum size and remain adequately free. Consult the service documentation instead of assuming every assignable address can be filled by application instances. If your arithmetic says there are 27 assignable addresses, write an estimate for permanent consumption, burst growth and resources needed during a replacement. The sum should fit inside the usable count with appropriate headroom.
Split a range and leave room for a change
Use 10.50.20.0/24 as the dairy’s first block for a paper exercise. The team wants four equal subnets, so it needs two bits to number them because 2^2 = 4. Taking two of the eight varying bits from the parent block gives the new /26 prefix. The last octet changes in steps of 64. Draw two Availability Zone columns and give each web and private app space. The same mathematical split would work in any order. The following order gives one clear plan to verify.
| Work area | CIDR | Block’s first and last addresses | Ordinary AWS assignable count |
|---|---|---|---|
| Web A | 10.50.20.0/26 | 10.50.20.0 through 10.50.20.63 | 59 |
| App A | 10.50.20.64/26 | 10.50.20.64 through 10.50.20.127 | 59 |
| Web B | 10.50.20.128/26 | 10.50.20.128 through 10.50.20.191 | 59 |
| App B | 10.50.20.192/26 | 10.50.20.192 through 10.50.20.255 | 59 |
Check the whole table rather than selecting a lucky row. Each first and last address fits the parent. Each start is one above the previous end. The four totals sum to 256, so the full block is accounted for. Each child also consumes its own reserved addresses. Four independent AWS subnets with 59 assignable positions each have 236 assignable positions collectively. A single /24 would have 251 under the ordinary reservation rule. The address tradeoff is one practical cost of splitting, even though separate subnets can support distinct placements and routes.
Now consider a larger business requirement. Each app zone might need 20 servers, with two private addresses per server in this teaching plan. That uses 40 addresses in App A and 40 in App B before any additional resources. A parallel rollout that temporarily keeps a second complete set could require 80 in one app subnet. A /26 with 59 assignable addresses would not fit that rollout. In the larger VPC, pick separate aligned app blocks large enough for the rollout and leave the unused parts documented. Explain the choice using the greatest expected simultaneous count rather than the initial server count.
For the web entry point also check current service requirements. For example, the Application Load Balancer subnet guidance calls for a CIDR of at least /27 and at least eight free IP addresses in every selected subnet so the load balancer can scale. Even a mathematically valid allocation must fit the resource that uses it. A planning sheet should include a read-only check of the production-like service’s subnet requirements before approving a lab design.
Allocate different sized blocks without leaving accidental gaps
Equal blocks make a good first exercise, but the dairy’s web entry and private app tiers need different amounts of address space. Give the app tier its largest practice block first. Inside 10.50.40.0/24, reserve 10.50.40.0/25 for App A. This covers .0 through .127. The remaining half starts at .128. You can assign 10.50.40.128/26 to a test app group, ending at .191.
Place a smaller practice subnet at 10.50.40.192/27 for a workload that fits its 27 assignable AWS IPv4 positions. That block ends at .223. Leave 10.50.40.224/27 as reserve. Draw the four pieces on one horizontal line. The large block starts on a 128 boundary, the medium block starts on a 64 boundary, and the smaller blocks start on 32 boundaries. Writing the largest allocations first makes it easier to keep the remaining space aligned.
Try another order on paper. If the first tiny allocation starts near the middle, ask whether the large block you want later can still fit as a single aligned contiguous range. You might end up with several small holes whose sizes add up to a large number while none of them can hold the next aligned block. Cloud networking plans have this problem when unrelated lab ranges were chosen without coordination. Record reserved and unused ranges as deliberately as assigned ones.
Use the planned ranges for placement, then attach routes for their actual needs. For example, a private app subnet can use a suitable outbound path and receive calls from a private entry tier. A public subnet can route assigned IPv4 public entry traffic through an internet gateway. The chosen prefix size alone does not assign either of those roles. Write the subnet’s CIDR, AZ, route table and intended callers in separate columns. The resulting plan is usable even when resources move or their friendly names change.
Explain a route match and rule out a range conflict
Suppose a subnet has routes that match 10.50.0.0/16, 10.60.0.0/16, and 0.0.0.0/0. The first identifies a local VPC range. The second is a planned private route to the distribution office. The third matches every IPv4 destination and serves as a default when nothing more specific applies. For 10.60.18.7, the office route supplies the matching destination. For 10.50.20.81, the VPC local route is the more specific match. An address outside both uses the default if it is available. The route’s target determines what the default path actually does.
Draw one mistake. A second company network also claims 10.50.0.0/16. A machine asked to send to 10.50.20.81 now has no unique way to distinguish which company’s machine you had in mind by the address alone. AWS VPC peering requires ranges that do not overlap. Choose ranges before joining networks or work through an explicitly supported overlap design with the network owners. Changing a single security group is not a repair for an ambiguous destination range.
To test overlap on paper, simplify two proposed blocks to their first and last addresses. Compare the ranges. For example, 10.50.32.0/20 spans third-octet values 32 through 47. The proposed 10.50.40.0/24 is completely inside it. You may divide the larger block into children on paper. You cannot treat the large and small range as separate nonoverlapping subnets in the same VPC allocation. Decide whether the larger block is a parent planning range or a deployed subnet.
Route summaries can be helpful in different designs. Two adjacent /26 ranges at .0 and .64 can be described by one aligned /25 route because the combined block starts at zero and ends at 127. Use a summary only when forwarding the whole summarized range to that target is intended. Do not include a neighboring range belonging to another network simply to shorten the list. Keep a table of the underlying assignments so a future engineer can verify which specific destinations belong there.
Check your paper allocation in an offline Python lab
Use Python 3 on your own computer. The standard ipaddress module checks ranges without contacting a network service. Before running the example, draw the four planned subnets in 10.50.20.0/24. Write the first and last address for one of them. Decide whether 10.50.20.81 belongs to the first or second subnet and whether it can be used under the ordinary AWS subnet rule.
from ipaddress import ip_address, ip_network
parent = ip_network("10.50.20.0/24")
address = ip_address("10.50.20.81")
children = list(parent.subnets(new_prefix=26))
for block in children:
first_assignable = block.network_address + 4
last_assignable = block.broadcast_address - 1
print(block, block.num_addresses, first_assignable, last_assignable)
if address in block:
print("example address belongs to", block)
Observe four rows. The first block begins at .0, has 64 total addresses and has an ordinary AWS assignable range of .4 through .62. The second begins at .64. Its assignable range is .68 through .126. The third begins at .128 and the fourth at .192. The additional line reports that 10.50.20.81 belongs to the second block. The number is also inside that block’s assignable part.
Read the code as two layers. Python’s network object calculates starts, sizes, ends and membership. The addition of four and subtraction of one describe this specific AWS exercise’s reserved positions. The standard library is not checking cloud service restrictions or occupied addresses. If you substitute an ordinary LAN example, rewrite the reservation arithmetic appropriately. If you substitute a special prefix such as /31, reason about that context instead of forcing the AWS formula onto it.
Now check which proposed range overlaps App A. In the interpreter, compare ip_network("10.50.20.64/26").overlaps(ip_network("10.50.20.96/27")). It returns true because the smaller block sits inside the larger one. Compare the earlier separate .128/26 range instead. That result is false. Leave these two tests in your notebook as examples of containment versus adjacency. A small visual helps: mark individual starting addresses, then draw the interval that extends from each start to its end.
If you try ip_network("10.50.20.81/26"), the ordinary strict network parser can reject the nonzero host bits. To see the network associated with a device address, use ip_interface and read its network property. This distinction is worth practicing because an AWS create command can normalize a supplied CIDR differently from an offline tool’s strict mode. Use the expected canonical network as the planned input. When finished, close the interpreter or remove only the temporary practice script if you saved one.
Inspect subnet capacity without deploying a new workload
If you have access to an authorized training VPC, open its Subnets list and select the right Region. Choose a subnet you are allowed to inspect. Record its VPC, CIDR, AZ, route-table association and available IPv4 count. Do the address math yourself first. For example, an ordinary /24 has 256 possible positions and 251 after the usual five reservations. Compare this maximum with the service’s observed free count. Existing resources explain why the free count can be smaller.
Now inspect two resources that use the subnet, such as practice instances or intended interfaces. Note one primary private IPv4 and check that it is inside the range. Read its security group and route requirements separately so you can explain the difference between allocated capacity and permitted communication. If you see an interface value that looks outside the planned CIDR, verify the actual VPC, subnet and secondary association before assuming the subnet calculation is wrong. You may be looking at a different resource.
For the paper version, use a subnet with 27 assignable positions and assume 17 are allocated. You have 10 free. A deployment that temporarily needs eight more could fit by this rough count and would leave two. Use the relevant service’s minimum free-space requirement and consider simultaneous replacements before accepting the plan. If your example service requires eight to remain free, the proposed deployment leaves too little. This is an address capacity decision as well as a launch count decision.
The inspection changes no route and creates no resources. Record the count, time and subnet ID for the exercise. Close the console when done. If a separate authorized lab intentionally creates subnets, remove only the disposable subnets after removing the resources that use them and the associations the lab no longer needs. Keep the organization’s approved VPC and shared resources out of the cleanup. Your success condition is a credible calculation backed by an observed resource and its network location.
Read the packet fields that matter after the prefix is decided
Now follow one IPv4 packet through the dairy network. Its source and destination are addresses. The IP protocol field tells the receiver what kind of upper-layer content follows, such as TCP or UDP. TCP’s ports live in the transport header carried inside the IP packet. The route table cares about the destination IP range. A firewall can separately decide whether to admit the protocol and ports. The packet’s address plan and the connection’s service plan are distinct. The packet makes it possible to apply both as it moves.
The IPv4 header also has a Time to Live field. A forwarding router reduces it and can discard the packet when it runs out. This keeps a routing mistake from circulating the packet indefinitely. A packet TTL is different from a DNS record’s time to live. The DNS value describes how long a lookup answer may be cached. IPv4’s forwarding TTL helps limit how far this particular packet can keep going. When the team reads a troubleshooting message, ask which of those two meanings applies before changing a record.
As an exercise, write three hops between the app and the office. Give the packet an illustrative TTL of four and subtract one at each forwarding router. After those three routers the remaining value is one. Now draw a bad route where one router sends it back to an earlier one. Eventually the forwarding limit is reached and the packet cannot keep circulating. A successful name lookup would not fix that network problem. Look at the matching destination route and selected next hop. A diagram with one repeated next hop often helps a novice see where the intended route diverged.
The IP header has a length as well. A particular network link has a maximum transmission unit, or MTU, describing the largest IP packet it can carry without requiring handling such as fragmentation. An instance can have an interface configured to send larger packets, while one segment of the destination path accepts only smaller ones. The effective path limit is constrained by the smallest segment. That difference matters if a short test request works but a larger transfer repeatedly stalls under the same routing and permissions.
For the beginner’s diagnosis, record the interface’s configured MTU, the path being used and one controlled comparison of small and larger operations against your own service. If somebody made a recent change to a tunnel or gateway, check that path’s documented requirements. IPv4 Path MTU Discovery uses information about a packet that is too large for the path so the sender can adjust. Network policies and endpoints need to support the appropriate operation. Do not tune every interface at once. Use the observed failures and the documented path limits to narrow the cause.
Plan a bigger subnet when the current range has reached its limit
Return to the dairy’s growing App A group. The subnet is 10.50.20.64/26 and its neighboring subnets are already used. Changing a document to call it a /25 would describe a range that covers a neighbor. Cloud subnet address ranges have to be chosen before placing workloads there, so plan a separate larger range in available VPC space. Give the replacement a name, AZ and route association that match the intended role. Check the actual address plan through your platform’s supported operation.
Begin with an inventory of what uses the old subnet. Include instances, network interfaces, secondary addresses, reserved addresses and managed resources if applicable. The subnet’s available-address count and the use recorded by your team should agree after allowing for platform reservations. If the console reports less free space than your paper plan, inspect which device or service consumes it. The fix might be a missing cleanup or an actual need for more space. Decide from the system’s observed state.
For a read-only training check, use the AWS CLI only with a permitted description role. Put the lab’s exact subnet ID and Region in your local variables, or insert their approved values directly. The query prints the CIDR, AZ and available IPv4 address count. It does not launch an instance or modify the subnet.
aws ec2 describe-subnets --subnet-ids "$SUBNET_ID" --region "$REGION" \
--query 'Subnets[0].{CIDR:CidrBlock,Zone:AvailabilityZone,FreeIPv4:AvailableIpAddressCount}'
Compare the result with the planned example and write down the time it was collected. A value of 12 free positions means 12 are available at that observation, not 12 incoming servers under every interface design. If each new app replica needs one primary and one secondary IPv4, six replicas can already use those 12. Add the free positions the platform or rollout expects to retain. A capacity estimate without the per-replica assumptions is difficult for another engineer to reproduce.
Write a simple migration plan on paper. Place new targets in the approved larger subnets, verify private routes and security groups, test their application response, and gradually move traffic with a known recovery path. Confirm what still uses the old subnet before removing resources. A working new target only verifies one part of the transition. The application, health checks, private data and approvals also need their own checks. End by comparing the planned and observed available counts and record the remaining capacity for the next team.
Review the range as another engineer would read it
Take the plan to a second student and ask them to spot three common errors. First, a row marked app reserve starts at 10.50.40.160/26. The written address is inside the .128/26 block. It does not start a new /26. The second student should correct the row to the intended aligned boundary or change the size and recalculate. A block that normalizes to an already allocated range is a plan conflict.
Second, a table marks 10.50.40.128/26 as private and attaches it to a route table whose default targets an internet gateway. Compare the route association with the intended design. A friendly name or RFC 1918 local address is not enough evidence for the subnet’s routing role. For a direct public IPv4 path, a public association and permitted listener also need to exist. A private app may reach selected outside destinations through its approved outbound networking without becoming a public destination.
Third, the planned connection to the distribution office includes B’s CIDR but nobody wrote the return route. On paper draw the request and reply. The request can reach its destination while the other side has no usable route back to the original range. That asymmetry shows why a design review checks both directions and both subnets’ actual associations. A separate permissions check is still needed on the destination. Write down the route target each direction uses instead of labeling the whole diagram “connected.”
Now present the corrected plan in five sentences. State the parent VPC range, each subnet role and AZ, the range and assignable count, which route applies to the cross-network example and the expected approved connection. If you can do this from the same table the other engineer sees, you have written a useful subnet plan. This small review practice turns binary arithmetic into an operating skill. You can hand the same sheet to a teammate who needs to understand or troubleshoot your AWS environment.
Work three subnet decisions on paper
- Find an aligned block. Write the network and last address for
10.50.19.40/20. The third octet belongs to the 16–31 block, so the start is10.50.16.0and the end is10.50.31.255. Verify the result by applying the partial mask of 240 to the third octet. - Check an AWS reservation decision. For
10.50.8.0/28, decide whether you can assign.2,.9, and.15under the normal subnet rule. Only.9is in the assignable example range. Write which positions the other two occupy in the complete block. - Compare two growth plans. A subnet needs 45 address positions now and 25 more at peak replacement time. Under the ordinary reservation rule, a
/26gives 59 and a/25gives 123. Consider the larger option and verify its aligned start and nonoverlap with other planned networks. Record the greatest expected usage, additional service headroom and the chosen range. - Read a private route. The destination is
10.60.18.7and the table contains a specific office route for10.60.0.0/16and a default for other IPv4 addresses. Circle the office route and explain how both entries match but the longer prefix is selected. Then list the separate permission you still need at the destination.
Interview questions and worked answers
How many addresses are in a /26, and how many can a normal AWS IPv4 subnet assign?
Six bits can vary, giving 64 total addresses. The ordinary AWS IPv4 subnet keeps five, so 59 remain assignable. Existing resources can occupy some of those 59. State the theoretical capacity and, if known, the actually free count separately.
How do you find the /20 network containing 10.50.35.19?
Four bits of the third octet belong to the prefix, creating a step of 16. A value of 35 lies in the block from 32 through 47, so the network starts at 10.50.32.0 and the last address is 10.50.47.255.
Why do two equal first three octets fail to prove addresses share a subnet?
A prefix such as /26 includes two additional bits in the last octet. Parts of that octet belong to different blocks. Read the configured mask and compare the complete ranges and placement before claiming both addresses are locally attached.
What changes when you split a /24 into four ordinary AWS /26 subnets?
The four child ranges cover the same 256 total addresses, but each child has five AWS reservations. The sum is four times 59 assignable positions, compared with 251 in an ordinary single /24. Splitting also gives choices about placement and routing.
Why does a subnet with enough addresses for current instances still need spare range?
During a release the old and new instances and their interfaces may exist simultaneously. A load balancer and other managed resources can have minimum free address requirements. Plan for peak concurrent consumption, not only steady-state servers.
How do you diagnose a peering request between two overlapping VPCs?
Identify all VPC ranges and calculate the overlap. Peering does not join VPCs with overlapping ranges. Work with the owners on a clear address plan or supported architecture for the overlapping networks. A wider firewall rule cannot provide a unique route for both networks.
Check the prefix and capacity calculation
What is the aligned network for
192.168.10.70/26:192.168.10.0/26,192.168.10.64/26, or192.168.10.128/26?Answer and reasoning
The
.64/26block. Steps of 64 put 70 between 64 and 127.What size remains if an engineer moves from a
/24to a/25: 256 or 128 total addresses?Answer and reasoning
128 total. The new prefix fixes one extra bit, cutting the count of combinations in half.
Does
10.50.40.0/24overlap10.50.32.0/20?Answer and reasoning
Yes. The
/20ends with third octet 47, and the entire.40range is contained in it.Which route has priority for
10.60.1.2when the table includes both10.60.0.0/16and0.0.0.0/0with valid targets?Answer and reasoning
The
/16is more specific. Its longer matching prefix is selected before the default.How many addresses can you normally assign in a new AWS
/28IPv4 subnet: 11, 14, or 16?Answer and reasoning
11. Four bits yield 16 addresses and five are reserved by the ordinary AWS subnet rule.
Revision cards
- Eight-bit octet
- Add 128, 64, 32, 16, 8, 4, 2 and 1 for the positions that are on. Four octets form the IPv4 address.
- Prefix and mask
- The prefix is the count of leading ones in the mask. An aligned network start has zeros in every remaining position.
- Block size
- An IPv4 prefix of length n gives two to the power of 32 minus n total addresses. Separate total, assignable and free.
- AWS subnet reserves
- For normal AWS IPv4 subnets, remove the first four and last from the total when estimating assignable positions.
- Adjacent and overlapping
- Adjacent ranges meet at successive addresses. Overlapping ranges contain at least one common address. Check both ends before building.
- Most specific route
- Among matching routes, forwarding uses the longer prefix, subject to the platform’s selection rules. Default matches all IPv4 destinations.
Technical references
- Internet Protocol and IPv4 addresses and CIDR prefixes and routing
- IPv4 address space for private internets and /31 point-to-point prefixes
- IPv4 special-purpose registrations
- AWS subnet sizing and reserved IPv4 addresses, Amazon-provided DNS and CreateSubnet address normalization
- VPC IPv4 CIDR blocks and VPC route selection
- VPC peering address overlap restrictions and Application Load Balancer subnet requirements
- Python’s IP address and network calculations
- IPv4 forwarding and TTL, IPv4 Path MTU Discovery and EC2 network MTU
- AWS CLI subnet details and available IPv4 count