Sorry if I'm using the wrong terminology. What I'm trying to ask is if it is safe to assume that IP addresses are from the same network if they differ only in the last octet?
TLDR: You can't safely make that assumption. Use a subnetting tool like http://subnetmask.info to quickly check it out
A "network" is a combination of the IP address and the subnet mask. The subnet mask defines the "size" of the network. A rather commonly found network/mask size is 24-bits (
255.255.255.0), in which case your thought would be correct and the first 3 octets determine the network while the last octet is the host.
I, on the other hand, frequently use different sized networks at my employment:
One of my DMZ nets is 22-bit (
255.255.252.0) in this case any of the 1022 address from
220.127.116.11-18.104.22.168 are all in the same network (note that the 3rd octet changes).
Another network for site-to-site VPN end points runs in a 28-bit (
255.255.255.240) network; only the 14 address from
22.214.171.124-126.96.36.199 are in the same network. But
188.8.131.52 (same 3rd octet, in fact, only 2 numbers away) is not in that network.
Most of the time and it depends.
"Same network" is a term you have to define.
Look into subnetting and how a subnet can be in different ranges.
You could f.ex easily have two VLANS (two different "networks") that are mapped to two /26 ranges in the same /24 subnet, which would immediately invalidate you hyphothesis.