How does WordPress tell which post is from which site in a multisite setup?

Posts from one site are not stored in the same table as posts from another site.

Each blog on a multi site gets an ID and that ID is used to generate a separate set of tables for each site in a multisite installation.

So for example site 1 gets:

wp_posts

where as site 2 gets:

wp_1_posts

and so on:

wp_2_posts