Network Security Groups (NSG) are used in Azure to control network traffic to and from resources. First, you create an NSG and add security rules with priorities. Then, you associate the NSG to a subnet or network interface. When traffic arrives, Azure checks the rules in priority order. The first rule that matches the traffic decides if it is allowed or denied. For example, if there is a rule allowing TCP traffic on port 80 with priority 100, and a deny all inbound rule with priority 200, traffic on port 80 is allowed, but traffic on other ports like 22 or 443 is denied. This process helps secure your network by controlling access. If no rule matches, traffic is denied by default. Associating NSGs to subnets or NICs applies these rules to all traffic entering or leaving those resources.