# 3.5.子網路(subnet)

* 網路遮罩(network mask)
  * 用"IP位址"及"網路遮罩"進行"AND位元運算", 算出來的就是"所屬的網路位址"
    * 例如26.2.21.198/255.0.0.0, 網路位址為11111111.00000000.000000000.00000000-> 26.0.0.0
    * 1稱為在乎位元, 0稱為不在乎位元
* 子網路(subnet): 將一個大網路切成許多子網路
* 子網路遮罩(subnet mask): 目的是透過子網路遮罩將網路切割成許多小網路
* 切割成子網路
  * ex 1. 在一個class C切出每個子網路有8個IP數(8台主機), 推算子網路遮罩及子網路數
    * 子網路遮罩: 11111111.11111111.11111111.11111000
    * 子網路數: 8-3=5
  * ex 2. 在一個class B切出每個子網路有32個IP數(32台主機), 推算子網路遮罩及子網路數
    * 子網路遮罩: 11111111.11111111.11111111.11100000
    * 子網路數: 16-5=11
  * ex 3. 在一個class C切出32個子網路, 推算子網路遮罩及主機數
    * 子網路遮罩: 11111111.11111111.11111111.11111000
    * 主機數: 8-5=3
  * ex 4. 在一個class B切出2048個子網路, 推算子網路遮罩及主機數
    * 子網路遮罩: 11111111.11111111.11111111.11100000
    * 主機數: 16-11=5
  * 分割subnet的步驟:
    * 1.先決定主機數, 或是子網路數
    * 2.計算適當的subnet mask
    * 3.列出所有的子網路及起訖IP
    * 4.經過subnet的切割後, 每個subnet的第一個IP要保留作為"網路位址代號", 最後一個IP要保留作為"網路廣播位置"
    * 5.剩餘可用IP = 所有IP - 第一個IP- 最後一個IP - 挑一個作為預設閘道IP


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jen-hsuan-hsieh.gitbook.io/protocol/chapter3-protocol-for-wireless-network/35zi-wang-8def28-subnet.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
