Bird
Raised Fist0
Interview Prepcomputer-networksmediumAmazonGoogleMicrosoftFlipkart

IP Addressing - IPv4, Subnet Mask, CIDR, Subnetting

Choose your preparation mode3 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Steps
setup

Initialize IP Address and Subnet Mask

The algorithm starts by defining the IPv4 address 192.168.1.130 and the subnet mask 255.255.255.192 (equivalent to /26). These values are prepared for processing.

💡 Initialization sets the stage for subnetting by establishing the IP and mask to analyze.
Line:ip_address = '192.168.1.130' subnet_mask = '255.255.255.192'
💡 Understanding the input values is crucial before any bitwise operations.
📊
IP Addressing - IPv4, Subnet Mask, CIDR, Subnetting - Watch the Algorithm Execute, Step by Step
Watching this step-by-step packet flow visualization helps you understand how IP addresses and subnet masks interact at a low level, making abstract concepts concrete and easier to grasp.
Step 1/10
·Active fillAnswer cell
IP address and subnet mask initialized.
Hop: 0
Host (192.168.1.130)
Router
Switch
DNS Server
src—:—
dst—:—
dataIP=192.168.1.130, Mask=255.255.255.192
IP address converted to binary for bitwise operations.
Hop: 1
Host (IP binary)
Router
Switch
DNS Server
📦Packet
fromclient
torouter
📄 payload11000000101010000000000110000010
🔌 protocolbinary
🚩 flags
src—:—
dst—:—
dataIP binary: 11000000101010000000000110000010
IP binary conversion: 192.168.1.130 → 11000000101010000000000110000010
Subnet mask converted to binary for bitwise AND.
Hop: 2
Host
Router (Mask binary)
Switch
DNS Server
📦Packet
fromrouter
toswitch
📄 payload11111111111111111111111111000000
🔌 protocolbinary
🚩 flags
src—:—
dst—:—
dataMask binary: 11111111111111111111111111000000
Subnet mask binary conversion: 255.255.255.192 → 11111111111111111111111111000000
Network address computed by bitwise AND.
Hop: 3
Host
Router
Switch (Network Address)
DNS Server
📦Packet
fromrouter
toswitch
📄 payload11000000101010000000000110000000
🔌 protocolbinary
🚩 flags
src—:—
dst—:—
dataNetwork binary: 11000000101010000000000110000000
Network address calculation by AND: IP & Mask → 11000000101010000000000110000000
Network address converted to dotted decimal.
Hop: 4
Host
Router
Switch (Network Address: 192.168.1.128)
DNS Server
src—:—
dst—:—
dataNetwork address: 192.168.1.128
Network address converted to dotted decimal: 192.168.1.128
Broadcast address computed by setting host bits to 1.
Hop: 5
Host
Router
Switch
DNS Server (Broadcast Address)
📦Packet
fromswitch
todns
📄 payload11000000101010000000000110111111
🔌 protocolbinary
🚩 flags
src—:—
dst—:—
dataBroadcast binary: 11000000101010000000000110111111
Broadcast address calculation: Network OR inverted mask → 11000000101010000000000110111111
Broadcast address converted to dotted decimal.
Hop: 6
Host
Router
Switch
DNS Server (Broadcast: 192.168.1.191)
src—:—
dst—:—
dataBroadcast address: 192.168.1.191
Broadcast address converted to dotted decimal: 192.168.1.191
Calculated usable hosts in subnet.
Hop: 7
Host
Router
Switch
DNS Server
src—:—
dst—:—
dataUsable hosts: 62
Usable hosts calculation: 2^(32-26) - 2 = 62
Subnet information summarized for output.
Hop: 8
Host
Router
Switch
DNS Server
src—:—
dst—:—
dataSummary: Network=192.168.1.128, Broadcast=192.168.1.191, Hosts=62
Subnet summary: Network=192.168.1.128, Broadcast=192.168.1.191, Usable hosts=62
Subnetting process complete; results output.
Hop: 9
Host
Router
Switch
DNS Server
src—:—
dst—:—
dataOutput: Network=192.168.1.128, Broadcast=192.168.1.191, Hosts=62
Final output: Network=192.168.1.128, Broadcast=192.168.1.191, Usable hosts=62

Key Takeaways

Subnetting is fundamentally a bitwise operation between the IP address and subnet mask.

This insight is difficult to grasp from code alone because the binary manipulation is abstract; seeing the bits flow clarifies the process.

The network address is the base address of the subnet, and the broadcast address is the highest address, both derived from the mask.

Visualizing these addresses as packets moving through nodes helps understand their derivation and significance.

The number of usable hosts depends on the number of host bits, which is the inverse of the mask's prefix length.

This relationship is often overlooked but is critical for network design; the visualization makes it explicit.

Practice

(1/5)
1. In which scenario is Source NAT (SNAT) most appropriately used within a private IPv4 network?
easy
A. When internal hosts initiate outbound connections to the internet, hiding their private IPs behind a public IP
B. When external users need to access a specific internal server via a public IP and port
C. When translating destination IP addresses for incoming packets to reach internal hosts
D. When mapping multiple public IPs to a single internal IP without port translation

Solution

  1. Step 1: Identify SNAT purpose

    SNAT modifies the source IP of outgoing packets, typically to allow multiple internal hosts to share a public IP for internet access.
  2. Step 2: Analyze options

    When internal hosts initiate outbound connections to the internet, hiding their private IPs behind a public IP correctly describes SNAT's role in outbound connections. When external users need to access a specific internal server via a public IP and port describes DNAT or port forwarding. When translating destination IP addresses for incoming packets to reach internal hosts is DNAT's function. When mapping multiple public IPs to a single internal IP without port translation is not typical SNAT behavior.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    SNAT = source IP translation for outbound traffic [OK]
Hint: SNAT changes source IP for outbound traffic
Common Mistakes:
  • Confusing SNAT with DNAT
  • Assuming SNAT handles inbound connections
  • Believing SNAT can map multiple public IPs to one internal IP without ports
2. Which of the following statements about HTTP 4xx and 5xx status codes is INCORRECT?
medium
A. 4xx status codes indicate client-side errors, meaning the client must modify the request to succeed.
B. 5xx status codes indicate server-side errors, meaning the server failed to fulfill a valid request.
C. A 403 status code means the client is forbidden from accessing the resource, even if authenticated.
D. A 404 status code means the server is temporarily unavailable and the client should retry later.

Solution

  1. Step 1: Review meanings of 4xx and 5xx status codes

    4xx = client errors; 5xx = server errors.
  2. Step 2: Analyze each statement

    4xx status codes indicate client-side errors, meaning the client must modify the request to succeed. is correct: 4xx means client must fix request.
    5xx status codes indicate server-side errors, meaning the server failed to fulfill a valid request. is correct: 5xx means server failed.
    A 404 status code means the server is temporarily unavailable and the client should retry later. is incorrect: 404 means 'Not Found', not temporary unavailability; 503 indicates temporary server unavailability.
    A 403 status code means the client is forbidden from accessing the resource, even if authenticated. is correct: 403 means forbidden access regardless of authentication.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    404 is about missing resource, not server availability.
Hint: 404 = Not Found, 503 = Service Unavailable
Common Mistakes:
  • Confusing 404 with temporary server errors
  • Assuming 403 means unauthenticated rather than forbidden
  • Mixing client and server error categories
3. Which of the following statements about TCP acknowledgment numbers is INCORRECT?
medium
A. TCP acknowledgment numbers are cumulative and indicate the next expected byte from the sender
B. Duplicate ACKs always indicate packet loss and require immediate retransmission
C. An ACK number can acknowledge multiple segments if they are received in order
D. ACK numbers help the sender detect which data has been successfully received

Solution

  1. Step 1: Review ACK number behavior

    ACK numbers are cumulative and indicate the next byte expected, acknowledging all prior bytes.
  2. Step 2: Analyze duplicate ACKs

    Duplicate ACKs often indicate packet loss but can also occur due to reordering; immediate retransmission is triggered only after three duplicates (fast retransmit).
  3. Step 3: Evaluate options

    TCP acknowledgment numbers are cumulative and indicate the next expected byte from the sender is correct. Duplicate ACKs always indicate packet loss and require immediate retransmission is incorrect because duplicate ACKs do not always require immediate retransmission. An ACK number can acknowledge multiple segments if they are received in order is correct as ACK numbers can acknowledge multiple segments. ACK numbers help the sender detect which data has been successfully received is correct.
  4. Final Answer:

    Option B -> Option B
  5. Quick Check:

    Duplicate ACKs signal potential loss but do not always trigger immediate retransmission.
Hint: Duplicate ACKs ≠ always immediate retransmit; need 3 duplicates.
Common Mistakes:
  • Assuming every duplicate ACK means packet loss
  • Confusing cumulative ACKs with selective ACKs
  • Believing ACK numbers acknowledge individual segments only
4. If a client crashes immediately after sending the final ACK in the TCP three-way handshake, what is the likely impact on the server's connection state?
hard
A. The server resets the connection upon detecting no ACK from the client
B. The server immediately closes the connection due to missing data
C. The server retransmits SYN-ACK packets until timeout, then closes the connection
D. The server considers the connection established and waits indefinitely for data

Solution

  1. Step 1: Understand handshake completion

    After the client sends the final ACK, the server marks the connection as established.
  2. Step 2: Consider client crash impact

    If the client crashes immediately after ACK, the server has no immediate way to detect this and will wait for data or timeout based on application-level timeouts.
  3. Step 3: Analyze options

    The server considers the connection established and waits indefinitely for data correctly states the server waits indefinitely (or until timeout). The server immediately closes the connection due to missing data is incorrect; server does not close immediately. The server retransmits SYN-ACK packets until timeout, then closes the connection is wrong; retransmission of SYN-ACK happens before handshake completes, not after. The server resets the connection upon detecting no ACK from the client is incorrect; server does not reset connection without explicit reset packet.
  4. Final Answer:

    Option D -> Option D
  5. Quick Check:

    Server trusts handshake completion after final ACK, unaware of client crash.
Hint: Server trusts final ACK; client crash after means server waits for data
Common Mistakes:
  • Assuming server detects client crash immediately
  • Confusing retransmission behavior post-handshake
  • Thinking server resets connection without RST packet
5. If a real-time chat application needs to support thousands of clients with intermittent connectivity and occasional message bursts, which limitation of WebSockets should be considered, and what fallback mechanism is most appropriate?
hard
A. WebSocket cannot handle intermittent connectivity; fallback to opening multiple WebSocket connections per client
B. WebSocket does not support message ordering; fallback to SSE to guarantee ordered delivery
C. WebSocket connections consume significant server resources per client; fallback to HTTP Long Polling to reduce persistent connections
D. WebSocket has high latency for message bursts; fallback to HTTP/2 multiplexing to improve throughput

Solution

  1. Step 1: Identify WebSocket resource usage

    Each WebSocket connection requires server resources to maintain persistent connections, which can be costly at scale.
  2. Step 2: Consider intermittent connectivity

    Clients with intermittent connectivity may cause connection drops, increasing server load.
  3. Step 3: Evaluate fallback options

    HTTP Long Polling can reduce persistent connections by using short-lived requests, making it a suitable fallback.
  4. Step 4: Analyze other options

    WebSocket does not support message ordering; fallback to SSE to guarantee ordered delivery is incorrect; WebSocket supports message ordering. WebSocket cannot handle intermittent connectivity; fallback to opening multiple WebSocket connections per client is wrong because opening multiple connections per client worsens resource usage. WebSocket has high latency for message bursts; fallback to HTTP/2 multiplexing to improve throughput misattributes latency issues to WebSocket and suggests unrelated HTTP/2 multiplexing.
  5. Final Answer:

    Option C -> Option C
  6. Quick Check:

    WebSocket resource cost + intermittent clients -> fallback to Long Polling
Hint: WebSocket scales poorly with many persistent connections; Long Polling reduces connection count
Common Mistakes:
  • Assuming WebSocket handles intermittent connectivity gracefully without resource impact
  • Believing WebSocket lacks message ordering
  • Confusing HTTP/2 multiplexing with WebSocket fallback