In more detail
When a device connects, it asks the DHCP server (usually the router) for a configuration. The reply lends it an address for a set lease time, along with the Subnet mask, Default gateway and DNS servers. DHCP uses UDP ports 67 (server) and 68 (client). Fixed addresses for printers or servers are set as reservations.