Linux Networking & TCP/IP for Developers · Lezione

Subnetting e CIDR in dettaglio

Padroneggi il variable-length subnet masking e la notazione CIDR per pianificare lo spazio degli indirizzi, calcolare gli intervalli e aggregare le route in modo efficiente.

Lezione 4 di 413 passaggi

Subnetting e CIDR in dettaglio è una lezione Linux Networking & TCP/IP for Developers gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Linux Networking & TCP/IP for Developers, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Linux Networking & TCP/IP for Developers include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

Why Subnetting Matters

Subnetting splits a large network into smaller, manageable segments. It improves security, performance, and address efficiency.

CIDR (Classless Inter-Domain Routing) replaced rigid class A/B/C boundaries with flexible prefix lengths.

CIDR Notation

A CIDR block is written as address/prefix. The prefix counts the number of leading network bits.

  • 192.168.1.0/24 — 24 network bits, 8 host bits
  • 10.0.0.0/8 — 8 network bits, 24 host bits

The Subnet Mask

A prefix maps directly to a dotted-decimal mask.

  • /24 = 255.255.255.0
  • /26 = 255.255.255.192
  • /30 = 255.255.255.252

Each set bit in the mask is a network bit.

Counting Hosts

Host count = 2^(host bits) minus 2 (network and broadcast addresses).

  • /24 -> 2^8 - 2 = 254 hosts
  • /26 -> 2^6 - 2 = 62 hosts
  • /30 -> 2^2 - 2 = 2 hosts (perfect for point-to-point links)

Finding the Network Address

Bitwise-AND the IP with the mask to get the network address. The example below computes it in Python.

import ipaddress
net = ipaddress.ip_network('192.168.5.130/26', strict=False)
print('network:', net.network_address)
print('broadcast:', net.broadcast_address)

Determining the Range

For 192.168.5.130/26: block size is 64, so subnets start at .0, .64, .128, .192.

The .130 address falls in the 192.168.5.128/26 subnet (usable .129 to .190, broadcast .191).

Variable-Length Subnet Masking (VLSM)

VLSM lets different subnets use different prefix lengths from one block, matching size to need.

Allocate largest subnets first to avoid fragmentation and wasted address space.

Route Aggregation (Supernetting)

Adjacent subnets can be summarized into one larger prefix, shrinking routing tables.

  • 192.168.0.0/24 + 192.168.1.0/24 -> 192.168.0.0/23

Aggregation only works when blocks are contiguous and aligned.

Subnetting with Python

The ipaddress module can split a network into smaller subnets automatically.

import ipaddress
big = ipaddress.ip_network('10.0.0.0/24')
for sub in big.subnets(new_prefix=26):
    print(sub)

Checking Membership

Verify whether an address belongs to a network — essential for ACLs and routing decisions.

import ipaddress
addr = ipaddress.ip_address('10.0.0.45')
net = ipaddress.ip_network('10.0.0.0/26')
print(addr in net)

Common Pitfalls

Watch out for:

  • Forgetting to subtract network and broadcast addresses
  • Misaligned aggregation that overlaps other blocks
  • Using /31 links (valid per RFC 3021 for point-to-point) without device support

Quick Check

Test your subnetting math.

Recap

You can now plan address space confidently:

  • Read and convert CIDR prefixes and masks
  • Calculate network, broadcast, and host ranges
  • Apply VLSM to size subnets to need
  • Aggregate contiguous blocks to shrink routing tables
  • Use Python's ipaddress module for verification

This underpins the IPv6, routing, and NAT topics in this course.

Gratis per iniziare

Impara Linux Networking & TCP/IP for Developers con un tutor IA — gratis

Scrivi ed esegui vero codice nel tuo browser, ricevi aiuto istantaneo da un tutor IA disponibile 24/7, e riprendi da dove hai lasciato sul web o nell'app.

Corsi
12
Lezioni
48

Domande Frequenti

La lezione «Subnetting e CIDR in dettaglio» è gratuita?

Sì — il testo completo di «Subnetting e CIDR in dettaglio» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Linux Networking & TCP/IP for Developers, passa a CoddyKit PRO. Il corso Linux Networking & TCP/IP for Developers include 4 lezioni in totale.

Cosa imparerò in «Subnetting e CIDR in dettaglio»?

Padroneggi il variable-length subnet masking e la notazione CIDR per pianificare lo spazio degli indirizzi, calcolare gli intervalli e aggregare le route in modo efficiente. Eserciti Linux Networking & TCP/IP for Developers con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Linux Networking & TCP/IP for Developers?

Non è richiesta alcuna esperienza precedente. Linux Networking & TCP/IP for Developers su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.

Quanto tempo richiede la lezione «Subnetting e CIDR in dettaglio»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Linux Networking & TCP/IP for Developers?

Sì. Ogni lezione Linux Networking & TCP/IP for Developers include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Indirizzamento e concetti IPv6
  2. Protocolli di routing avanzati (RIP/OSPF)
  3. Network Address Translation (NAT)
  4. Subnetting e CIDR in dettaglio
← Torna a Linux Networking & TCP/IP for Developers