How did you think that the system knew where the partitions were?
The locations of the partitions on your disc are stored as records in a table, known as … wait for it … the partition table, that is written to the disc where the partitions themselves are. (It's not strictly necessary for a partition table to live on the same disc as the partitions themselves. But this idea is rare to practically nonexistent in the personal computing world, and is beyond the scope of this answer.)
As you've seen, there are various kinds of partition tables. They are structured quite differently from one another, and what David Dai said about them living at the start of the disc is only true for some of them. What's important is that they live, at least partly, in a fixed and well-known place on the disc. For examples:
- The EFI partition table occupies two places on the disc: a few sectors at the beginning of the disc and a few sectors at the end of the disc. A "header" record in a fixed position at logical sector #1, also mirrored in a well-known position in the very last sector of the disc, shows the sizes and locations of the table records proper.
- The old "MBR" style partition table is distributed across the disc, but starts with a fixed set of four "primary" table entries in logical sector #0 of the disc which (potentially, subject to a whole load of ifs and buts that are outwith the scope of this answer) point to singly-linked lists of "extended" entries in other, variable, places.
- The BSD disklabel scheme (when used natively) has a table of 8 partition records in logical sector #0 of the disc.
Discs don't start out with partition table data structures written to them. Reading a partition table usually, in a heterogeneous world, thus involves looking in the fixed and well-known places for signature words and performing checksum validations, to ensure that a partition table of a particular type is actually on the disc in the first place. Creating a partition table is the act of writing to a disc the necessary signatures, checksums, and null entries to form a valid, but empty, partition table of a particular type. Creating a partion is merely the act of adding a record to such a table. (Then comes formatting a partition of course.)