A disk drive typically has a layer of material that can be magnetized in any direction. At any moment in time, a drive head can either be in "read" mode (record changes in the magnetic field that moves under it) or in "write" mode (force the magnetic field near the head into a particular orientation). To allow for "random" access, the surface of the drive contains a "start of sector header" pattern at the start of each sector, each followed by a sector number. These headers are written when the disk is low-level formatted and never again after that. Following each complete header will be a "start of sector" pattern which is immediately followed by a sector's worth of data.
To read a sector, the drive controller will move the head to the track containing the sector and then wait until it sees a start of sector header pattern, followed by the number of the sector to be read. Once it sees that, it will wait for the next "start of sector" pattern and then retrieve the data that follows it.
To write a sector, the drive controller will locate the sector header as described above, but as soon as it is observed the drive will switch the head to write mode and then, oblivious to what may be under the head at the time, write out a sector header followed by a sector's worth of data, and then switch back to read mode. If the drive has been properly formatted, the drive will switch out of write mode before it obliterates anything other than the sector it was trying to write. If the drive hasn't been properly formatted, all bets are off.
Modern hard drives add additional complications by having some track-identifying information recorded further below the surface of the disk than normal data, in a way that isn't disturbed by normal write operations, but which can be read--even while writing using a second coil on the same head assembly. The same principle applies, though--the disk contains markers which will never be overwritten during normal use, which tell the drive where to read or write sectors of data, but during the actual write operation the drive will be oblivious to anything that had been in the sector previously.