Nameservers, as the name suggests defines the named servers.
Named servers are "NS1.DOMAIN.COM" and "NS2.DOMAIN.COM" minimum, usually they point to a single IP address, although it is recommended that NS1.DOMAIN.COM points to a different static IP address as opposed to NS2.DOMAIN.COM. This is because, in the unlikely event that one of your IP addresses fails to work, the secondary ip address should work.
So, similarly to how telephones work. You want to call your friend, you know your friends mobile number.. but it's easier to remember your friend by a name, rather than the 11 digits. IP addresses and NameServers operate in the same way, it's easier to remember "facebook.com" or "google.com" than it is their IP addresses.
Therefore, you store NS1.DOMAIN.COM to one of your primary IP address, and NS2.DOMAIN.COM to the secondary IP address. So, when someone punches your domain name in the address bar, that request escalates to a router which knows where to find the DNS record of "NS1.DOMAIN.COM" and translates that to the IP address, then forwards the request (client) to that server.
Additional, virtual hosts, hosted on your server will point to the same DNS records, for example "NS1.DOMAIN.COM", which collects the IP address for that named server.
Your webservice (Apache/nginx) is then responsible for handling the individual requests that are forwarded to your server, which at this point, your DNS is done with.
In short - nameservers are just DNS records which name your server IP addresses, upto 4 unique IP addresses, and they are only defined as fall back, should the first IP/name server fail to respond.