Classless Inter Domain Routing

IPv4

Most people are used to class A, B and C networks. These have the following IP numbers and net masks:
A:   1.0.0.0 ... 127.255.255.255   255.0.0.0
B: 128.0.0.0 ... 191.255.255.255 255.255.0.0
C: 192.0.0.0 ... 223.255.255.255 255.255.255.0
127.0.0.1 is reserved for the loopback, with network address 127.0.0.0, netmask 255.0.0.0 and 127.255.255.255 as its broadcast address.
0.0.0.0 is the entire Internet with netmask 0.0.0.0 and 255.255.255.255 as its broadcast address.

CIDR does not link the number of hosts to the network address, at least not in the strict way that 'classic' A, B and C networks do. Furthermore, it doesn't limit the size to 16M, 64k or 256 IP nrs. Instead, any power of 2 can be used as a size of the network (number of hosts + network address + broadcast address). In other words, CIDR sees an IP nr as a 32 bit rather than a 4 byte address.

Net masks

The following table shows the net masks in a binary form. The 'CIDR' column is the number of '1's from left to right.
Binary                             Hex           Dec               CIDR   Numer of addresses

00000000000000000000000000000000   00:00:00:00   0.0.0.0           /0	  4,294,967,296     4 G
10000000000000000000000000000000   80:00:00:00   128.0.0.0         /1     2,147,483,648     2 G
11000000000000000000000000000000   C0:00:00:00   192.0.0.0         /2     1,073,741,824     1 G
11100000000000000000000000000000   E0:00:00:00   224.0.0.0         /3       536,870,912   512 M
11110000000000000000000000000000   F0:00:00:00   240.0.0.0         /4       268,435,456   256 M
11111000000000000000000000000000   F8:00:00:00   248.0.0.0         /5       134,217,728   128 M
11111100000000000000000000000000   FC:00:00:00   252.0.0.0         /6        67,108,864    64 M
11111110000000000000000000000000   FE:00:00:00   254.0.0.0         /7        33,554,432    32 M
11111111000000000000000000000000   FF:00:00:00   255.0.0.0         /8        16,777,216    16 M
11111111100000000000000000000000   FF:80:00:00   255.128.0.0       /9         8,388,608     8 M
11111111110000000000000000000000   FF:C0:00:00   255.192.0.0       /10        4,194,304     4 M
11111111111000000000000000000000   FF:E0:00:00   255.224.0.0       /11        2,097,152     2 M
11111111111100000000000000000000   FF:F0:00:00   255.240.0.0       /12        1,048,576     1 M
11111111111110000000000000000000   FF:F8:00:00   255.248.0.0       /13          524,288   512 k
11111111111111000000000000000000   FF:FC:00:00   255.252.0.0       /14          262,144   256 k
11111111111111100000000000000000   FF:FE:00:00   255.254.0.0       /15          131,072   128 k
11111111111111110000000000000000   FF:FF:00:00   255.255.0.0       /16           65,536    64 k
11111111111111111000000000000000   FF:FF:80:00   255.255.128.0     /17           32,768    32 k
11111111111111111100000000000000   FF:FF:C0:00   255.255.192.0     /18           16,384    16 k
11111111111111111110000000000000   FF:FF:E0:00   255.255.224.0     /19            8,192     8 k
11111111111111111111000000000000   FF:FF:F0:00   255.255.240.0     /20            4,096     4 k
11111111111111111111100000000000   FF:FF:F8:00   255.255.248.0     /21            2,048     2 k
11111111111111111111110000000000   FF:FF:FC:00   255.255.252.0     /22            1,024     1 k
11111111111111111111111000000000   FF:FF:FE:00   255.255.254.0     /23              512
11111111111111111111111100000000   FF:FF:FF:00   255.255.255.0     /24              256
11111111111111111111111110000000   FF:FF:FF:80   255.255.255.128   /25              128
11111111111111111111111111000000   FF:FF:FF:C0   255.255.255.192   /26               64
11111111111111111111111111100000   FF:FF:FF:E0   255.255.255.224   /27               32
11111111111111111111111111110000   FF:FF:FF:F0   255.255.255.240   /28               16
11111111111111111111111111111000   FF:FF:FF:F8   255.255.255.248   /29                8
11111111111111111111111111111100   FF:FF:FF:FC   255.255.255.252   /30                4
11111111111111111111111111111110   FF:FF:FF:FE   255.255.255.254   /31                2
11111111111111111111111111111111   FF:FF:FF:FF   255.255.255.255   /32                1
What used to be class A is now '/8', B is '/16', C is '/24' and '32' is the 'netmask' for a single host.

Networks

The bits in the 'host' part of a network address are all '0'. Bits left of the 'hosts' bits can be either '0' or '1' (this is rather like sub netting a classic A, B or C address).
The following table/graph shows a network being split in smaller networks and than being split again, etc.
    Netmask:
    0   128   192   224   240   248   252

    0-+-->0-+-->0-+-->0-+-->0-+-->0-+-->0 (00)    Network address (hex)
      |     |     |     |     |     |
      |     |     |     |     |     +-->4 (04)
      |     |     |     |     |
      |     |     |     |     +-->8-+-->8 (08)
      |     |     |     |           |
      |     |     |     |           +->12 (0C)
      |     |     |     |
      |     |     |     +->16-+->16-+->16 (10)
      |     |     |           |     |
      |     |     |           |     +->20 (14)
      |     |     |           |
      |     |     |           +->24-+->24 (18)
      |     |     |                 |
      |     |     |                 +->28 (1C)
      |     |     |
      |     |     +->32-+->32-+->32-+->32 (20)
      |     |           |     |     |
      |     |           |     |     +->36 (24)
      |     |           |     |
      |     |           |     +->40-+->40 (28)
      |     |           |           |
      |     |           |           +->44 (2C)
      |     |           |
      |     |           +->48-+->48-+->48 (30)
      |     |                 |     |
      |     |                 |     +->52 (34)
      |     |                 |
      |     |                 +->56-+->56 (38)
      |     |                       |
      |     |                       +->60 (3C)
      |     |
      |     +->64-+->64-+->64-+->64-+->64 (40)
      |           |     |     |     |
      |           |     |     |     +->68 (44)
      |           |     |     |
      |           |     |     +->72-+->72 (48)
      |           |     |           |
      |           |     |           +->76 (4C)
      |           |     |
      |           |     +->80-+->80-+->80 (50)
      |           |           |     |
      |           |           |     +->84 (54)
      |           |           |
      |           |           +->88-+->88 (58)
      |           |                 |
      |           |                 +->92 (5C)
      |           |
      |           +->96-+->96-+->96-+->96 (60)
      |                 |     |     |
      |                 |     |     +>100 (64)
      |                 |     |
      |                 |     +->104+>104 (68)
      |                 |           |
      |                 |           +>108 (6C)
      |                 |      
      |                 +>112-+->112+>112 (70)
      |                       |     |
      |                       |     +>116 (74)
      |                       |
      |                       +->120+>120 (78)
      |                             |
      |                             +>124 (7C)
      |
      +->128+->128+->128+->128+->128+>128 (80)
            |     |     |     |     |
            |     |     |     |     +>132 (84)
            |     |     |     |
            |     |     |     +->136+>136 (88)
            |     |     |           |
            |     |     |           +>140 (8C)
            |     |     |
            |     |     +->144+->144+>144 (90)
            |     |           |     |
            |     |           |     +>148 (94)
            |     |           |
            |     |           +->152+>152 (98)
            |     |                 |
            |     |                 +>156 (9C)
            |     |
            |     +->160+->160+->160+>160 (A0)
            |           |     |     |
            |           |     |     +>164 (A4)
            |           |     |
            |           |     +->168+>168 (A8)
            |           |           |
            |           |           +>172 (AC)
            |           |
            |           +->176+->176+>176 (B0)
            |                 |     |
            |                 |     +>180 (B4)
            |                 |
            |                 +->184+>184 (B8)
            |                       |
            |                       +>188 (BC)
            |
            +->192+->192+->192+->192+>192 (C0)
                  |     |     |     |
                  |     |     |     +>196 (C4)
                  |     |     |
                  |     |     +->200+>200 (C8)
                  |     |           |
                  |     |           +>204 (CC)
                  |     |
                  |     +->208+->208+>208 (D0)
                  |           |     |
                  |           |     +>212 (D4)
                  |           |
                  |           +->216+>216 (D8)
                  |                 |
                  |                 +>220 (DC)
                  |
                  +->224+->224+->224+>224 (E0)
                        |     |     |
                        |     |     +>228 (E4)
                        |     |
                        |     +->232+>232 (E8)
                        |           |
                        |           +>236 (EC)
                        |
                        +->240+->240+>240 (F0)
                              |     |
                              |     +>244 (F4)
                              |
                              +->248+>248 (F8)
                                    |
                                    +>252 (FC)

IPv6

IPv6 works the same way. The numbers are just bigger.

Per bit

Netmask binary     Hex    CIDR

0000000000000000   0000   /0
1000000000000000   8000   /1
1100000000000000   c000   /2
1110000000000000   e000   /3
1111000000000000   f000   /4
1111100000000000   f800   /5
1111110000000000   fc00   /6
1111111000000000   fe00   /7
1111111100000000   ff00   /8
1111111110000000   ff80   /9
1111111111000000   ffc0   /10
1111111111100000   ffe0   /11
1111111111110000   fff0   /12
1111111111111000   fff8   /13
1111111111111100   fffc   /14
1111111111111110   fffe   /15
1111111111111111   ffff   /16
'ffff' in IPv6 is the same as '255.255' in IPv4.

Per 16 bits

Netmask                                   CIDR   2ⁿ     Number of addresses

0000:0000:0000:0000:0000:0000:0000:0000   /0     2¹²⁸   340,282,366,920,938,463,463,374,607,431,768,211,456
ffff:0000:0000:0000:0000:0000:0000:0000   /16    2¹¹²         5,192,296,858,534,827,628,530,496,329,220,096
ffff:ffff:0000:0000:0000:0000:0000:0000   /32    2⁹⁶                 79,228,162,514,264,337,593,543,950,336
ffff:ffff:ffff:0000:0000:0000:0000:0000   /48    2⁸⁰                      1,208,925,819,614,629,174,706,176
ffff:ffff:ffff:ffff:0000:0000:0000:0000   /64    2⁶⁴                             18,446,744,073,709,551,616    16 Z
ffff:ffff:ffff:ffff:ffff:0000:0000:0000   /80    2⁴⁸                                    281,474,976,710,656   256 T
ffff:ffff:ffff:ffff:ffff:ffff:0000:0000   /96    2³²                                          4,294,967,296     4 G
ffff:ffff:ffff:ffff:ffff:ffff:ffff:0000   /112   2¹⁶                                                 65,536    64 k
ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff   /128   2⁰                                                       1

':0000:' can be written as ':0:'. And a long sequence of zeros as '::'.
Since the IPv6 internet is 2000::/3 (2000:0000:0000:0000:0000:0000:0000:0000 to 3fff:ffff:ffff:ffff:ffff:ffff:ffff:ffff), the number of available addresses is 2¹²⁵ = 42,535,295,865,117,307,932,921,825,928,971,026,432.

Combine host and network in one statement

Suppose I have a host '2001:0db8:1234:1::1/128' and a network '2001:0db8:1234:1::/64'. One can combine both statements (EG in ifconfig) in one statement; '2001:0db8:1234:1::1/64'.

IPv6 Ready