M4RKYU.SYSEdition 2027
Skip to content
LOCZH/安大略 · 加拿大/▸logs · how to determine the network address from a known ip address 4895待机OK/--:--:--EST
M4M4RK_YUportfolio
  • 创作创作
    创作Overview
    • 作品精选案例与项目记录
    • 游戏可玩原型与游戏开发日志
  • 影像影像
    影像Overview
    • 照片影像合集与视觉实验
    • 商店印刷品、海报和限量物件
  • 写作写作
    写作Overview
    • 博客长篇开发日志与现场笔记
    • 笔记短观察、链接与代码片段
  • 资源资源
    资源Overview
    • 工具38 款浏览器内开发工具
    • 链接每日使用的开发与设计书签
  • 关于关于
  • 联系联系
EN

同步 · dev.to / @markyu

Network Address Calculation: The Subnet Math That Matters

A practical subnetting guide showing how to calculate a network address from an IP address and mask using binary math and simple examples.

发布日期
Oct 16 '24
·
阅读时长
2 min read
·
点赞
5
networkingbeginnersdevopssecurity
在 dev.to 查看

本页目录

  • The Rule
  • Example: 192.168.10.37/24
  • Example: 192.168.10.37/26
  • Quick Mental Shortcut
  • Python Check
  • Why Developers Should Care
  • Final Thought

Subnet math feels annoying until you need to debug a firewall rule, Kubernetes network policy, VPN route, or cloud security group.

Then suddenly this question matters:

Given an IP address and subnet mask, what network is it actually in?

Let’s calculate it directly.

The Rule

network address = IP address AND subnet mask

That is it.

The AND operation compares bits:

IP bitMask bitResult
000
010
100
111

Example: 192.168.10.37/24

/24 means the subnet mask is:

255.255.255.0

IP:

192.168.10.37

Mask:

255.255.255.0

Network:

192.168.10.0

With /24, the first three octets are the network part. The last octet is host space.

Example: 192.168.10.37/26

/26 is more interesting.

Mask:

255.255.255.192

The last octet in binary:

IP:   37  = 00100101
Mask: 192 = 11000000
AND:       00000000

So the network address is:

192.168.10.0/26

The /26 networks in the last octet move in blocks of 64:

NetworkHost range
192.168.10.0/26.1 - .62
192.168.10.64/26.65 - .126
192.168.10.128/26.129 - .190
192.168.10.192/26.193 - .254

37 falls into the first block.

Quick Mental Shortcut

For masks in the last octet:

block size = 256 - mask_octet

For /26:

256 - 192 = 64

So networks start at:

0, 64, 128, 192

Find the block that contains the IP.

Python Check

import ipaddress

ip = ipaddress.ip_interface("192.168.10.37/26")
print(ip.network)

Output:

192.168.10.0/26

This is what I use when I do not want to trust my tired brain during network debugging.

Why Developers Should Care

Subnet mistakes show up in:

  • cloud VPC rules
  • Docker/Kubernetes networking
  • VPN routing
  • database allowlists
  • office network debugging
  • zero-trust access rules

One wrong CIDR can expose too much or block the service you need.

Final Thought

Subnetting is not glamorous, but it is one of those fundamentals that saves time when production networking gets weird.

What subnet or CIDR mistake has bitten you before?

相关阅读

Docker Containers: The Commands That Prove Isolation

A practical Docker container guide focused on the commands that show image layers, process isolation, networking, volumes, and debugging.

docker

Frontend Linear Data Structures Deep Dive: Arrays, Stacks, Queues, and Linked Lists

The Big Picture Before diving into stacks, queues, and linked lists, it helps to know...

computerscience

JS Sorting Algorithms Every Developer Should Know

You call .sort() every day without thinking about it. But the sorting algorithm your language's...

algorithms

原文发布

本文首发于 dev.to,评论与点赞保留在原站。

在 dev.to 继续阅读
上一篇Java BeanUtils Copying: Convenient, but Not FreeA practical Java guide to BeanUtils, shallow copy pitfalls, reflection overhead, and when MapStruct or manual mapping is a better choice.
返回全部文章
下一篇Bad Data Quality Costs More Than a Slow QueryA practical data quality guide for engineers: validation, ownership, schema drift, observability, and fixing bad data before dashboards lie.
返回档案
M4RKYUM4RKYUM4RKYUM4RKYUM4RKYUM4RKYUM4RKYUM4RKYU
始于 2024
ZhenXiao Mark YuZhenXiao Mark Yu
联系

看到什么有意思的?和我聊聊。

这是一个作品集,不是服务 · 但每一条留言我都会看 — 如果哪里让你有所触动,或者只想打个招呼,欢迎写信过来。

开启对话
频道开放

随时打个招呼 · 2026

--:--:--EST加拿大 安大略
  • 邮件
  • GitHub
  • dev.to
  • 领英
  • 推特 / X
  • Instagram
  • Facebook
  • YouTube
  • CodePen
  • Spotify
  • Snapchat

订阅

偶尔收到一封简讯

来自 m4rkyu.com 的笔记与日志——简短、标注日期、没有杂音。随时可退订。

作品

线上发布、游戏作品与视觉档案。

  • 项目
  • 游戏
  • 档案
  • 日志

资源

每日好用的工具与个人收藏的链接库。

  • 搜索
  • 最新
  • 工具
  • 链接
  • 笔记
  • 主题
  • 商店
RSSJSON Feed

工作室

背景、联系方式以及合作渠道。

  • 关于
  • 联系
  • 更新日志
  • 技术说明
  • 简历筹备中

社交

在常去的平台上找到我。

  • GitHub
  • dev.to
  • 领英
  • 推特 / X
  • Instagram
  • Facebook
  • YouTube
  • CodePen
  • Spotify
  • Snapchat
  • 邮件
© 2026 ZhenXiao Mark Yumarkyu0615@gmail.com
  • 邮件
  • GitHub
  • dev.to
  • 领英
  • 推特 / X
  • Instagram
  • Facebook
  • YouTube
  • CodePen
  • Spotify
  • Snapchat
隐私条款由 Next.js 16 · React 19 · Tailwind 4 构建