There are many possibilities.
Some file formats, like PDF as described by Keith, and Authenticode for Microsoft Windows executables, put the signature in the file but arrange for it not to cover itself, and perhaps not some other non-critical data as well.
Some file or message formats, like XMLdsig and optionally S/MIME CMS/PKCS7 and PGP, put both the data and the signature in a larger file structure so that they can easily be separated, the signature verified, and the data (without the signature) used. Java codesigning uses Java's JAR format, which is a slightly modified ZIP file: each class (or other resource) is an entry in the JAR file, the digests of all classes are listed in the manifest which is also an entry in the JAR file, and the signature of the manifest plus related certificate(s) are stored in two additional entries in the JAR file.
Sometimes people just put the signature in a separate file that is linked to the data file; S/MIME CMS/PKCS7 and PGP 'detached' signatures do this. For example, a software download site might have one file named superwondergizmo-1.2.3.tar
and its signature in a file named superwondergizmo-1.2.3.tar.sig
(or sometimes ...asc
for 'armored' aka ASCII PGP). On modern Windows with NTFS it could make sense to use a supplemental stream to store the signature, but I've never seen anyone do so; similarly for MacOS with the resource fork; but those wouldn't usually work for transfer, which is often important nowadays.