Networking Fundamentals · Topic 3 of 5
IP Addressing, IPv4, IPv6 and Binary
Learn IPv4 addresses and subnet masks, prefix length, private ranges, IPv6 format and address types, and decimal to binary conversion for JN0-106.
- 5 min
- Bit values: 128, 64, 32, 16, 8, 4, 2, 1.
- Usable hosts = 2 to the power of host bits, minus 2; /30 gives 2 hosts.
- Private IPv4: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16.
What it is
A Layer 3 address identifies an interface across networks, not just on one segment. It has two parts: the network (prefix) part that routers use to forward, and the host part that identifies the interface inside that network.
The subnet mask or prefix length says where the network part ends. IPv4 addresses are 32 bits and IPv6 addresses are 128 bits. Because masks are binary, you need fast decimal to binary conversion to work with them.
How it works
Decimal to binary conversion
Each IPv4 octet is 8 bits. Every bit has a fixed value.
| Bit | 1st | 2nd | 3rd | 4th | 5th | 6th | 7th | 8th |
|---|---|---|---|---|---|---|---|---|
| Value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
To convert decimal to binary, subtract the largest value that fits, write a 1, and move on; write a 0 where it does not fit. Example: 172 = 128 + 32 + 8 + 4, so 172 is 10101100. To convert back, add the values of the 1 bits: 11000000 is 128 + 64 = 192.
Subnet masks and prefix length
A mask is a run of 1 bits (network) followed by 0 bits (host). The prefix length counts the 1 bits.
| Prefix | Mask | Hosts per subnet |
|---|---|---|
| /8 | 255.0.0.0 | 16,777,214 |
| /16 | 255.255.0.0 | 65,534 |
| /24 | 255.255.255.0 | 254 |
| /25 | 255.255.255.128 | 126 |
| /26 | 255.255.255.192 | 62 |
| /27 | 255.255.255.224 | 30 |
| /28 | 255.255.255.240 | 14 |
| /29 | 255.255.255.248 | 6 |
| /30 | 255.255.255.252 | 2 |
| /31 | 255.255.255.254 | 2, point to point only |
| /32 | 255.255.255.255 | 1, a host route such as a loopback |
Usable hosts are 2 to the power of host bits, minus 2. The first address is the network address and the last is the broadcast address. Junos OS writes addresses with the prefix length:
user@router# set interfaces ge-0/0/0 unit 0 family inet address 192.168.10.1/24
IPv4 address classes and special ranges
Classes are no longer used for routing, but the exam still expects you to recognize them.
| Class | First octet | Default mask |
|---|---|---|
| A | 1 to 126 | /8 |
| B | 128 to 191 | /16 |
| C | 192 to 223 | /24 |
| D (multicast) | 224 to 239 | None |
| E (reserved) | 240 to 255 | None |
| Range | Use |
|---|---|
| 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 | Private addresses (RFC 1918), not routed on the internet |
| 127.0.0.0/8 | Loopback |
| 169.254.0.0/16 | Link-local, used when no address is assigned |
| 0.0.0.0/0 | Default route |
IPv6 addresses
An IPv6 address is 128 bits, written as eight groups of four hexadecimal digits separated by colons.
Two rules shorten it:
- Drop leading zeros in any group:
0db8becomesdb8. - Replace one run of all zero groups with
::, but only once per address.
So 2001:0db8:0000:0000:0000:0000:0000:0001 becomes 2001:db8::1.
| Type | Prefix | Notes |
|---|---|---|
| Global unicast | 2000::/3 | Routable on the internet |
| Unique local | fc00::/7 | Private use, similar to RFC 1918 |
| Link-local | fe80::/10 | Every IPv6 interface has one; not routed |
| Multicast | ff00::/8 | Replaces broadcast |
| Loopback | ::1/128 | The local host |
| Unspecified | ::/128 | No address yet |
A LAN subnet is normally a /64, leaving 64 bits for the interface ID. IPv6 has no broadcast; it uses multicast instead.
user@router# set interfaces ge-0/0/0 unit 0 family inet6 address 2001:db8:1::1/64
IPv4 and IPv6 compared
| IPv4 | IPv6 | |
|---|---|---|
| Length | 32 bits | 128 bits |
| Notation | Dotted decimal | Hexadecimal with colons |
| Broadcast | Yes | No, multicast instead |
| Address resolution | ARP | Neighbor discovery (ICMPv6) |
| Junos family | family inet | family inet6 |
| Main routing table | inet.0 | inet6.0 |
The Junos protocol family names matter. IPv4 is family inet and its table is inet.0; IPv6 is family inet6 and its table is inet6.0.
Common mistakes
Counting the network and broadcast addresses as hosts. A /24 has 256 addresses but only 254 usable hosts.
Using :: twice. An address such as 2001::1::5 is invalid because the reader cannot tell how many zero groups each :: replaces.
Calling 127 a Class A network address for hosts. 127.0.0.0/8 is reserved for loopback, which is why Class A ends at 126.
Do not mix up the IPv6 link-local prefix fe80::/10 with the unique local prefix fc00::/7. Link-local is never routed; unique local can be routed inside an organization.
What to remember for the exam
- Bit values: 128, 64, 32, 16, 8, 4, 2, 1.
- Usable hosts = 2 to the power of host bits, minus 2; /30 gives 2 hosts.
- Private IPv4: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16.
- IPv6 is 128 bits;
::can appear only once; leading zeros may be dropped. - Link-local fe80::/10, global unicast 2000::/3, multicast ff00::/8, loopback ::1.
- IPv6 has no broadcast; LAN subnets are /64.
- Junos:
family inetandinet.0for IPv4,family inet6andinet6.0for IPv6.
Check yourself
What is 11100000 in decimal, and which prefix length gives that last mask octet?
224, which is 128 + 64 + 32; it is the last octet of a /27 mask, 255.255.255.224.
How many times can the double colon appear in one IPv6 address, and why?
Only once, because a second one would make it impossible to tell how many zero groups each replaces.
How many usable hosts does a /28 subnet have?
14, because 4 host bits give 16 addresses minus the network and broadcast addresses.
Topic 3 of 5 in Networking Fundamentals
Test yourself on Networking Fundamentals
The full Juniper JNCIA-Junos JN0-106 question bank has 1,155 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Juniper. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.