Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Just a curious question, how does a computer work out what file tyue a certain file is. E.G. How does a computer work out that this pages is a type of html? of each file, s there header information in the binary? Ram allocation? how does it know this?

share|improve this question

migrated from Aug 25 '12 at 10:37

This question came from our site for professional and enthusiast programmers.

For local files, it'll normally look for "magic" identifiers at (or at least toward) the beginning of the content. If it doesn't find that, it'll typically look at the name. For stuff off the web, MIME types are usually used to identify content type. – Jerry Coffin Aug 24 '12 at 21:34
up vote 3 down vote accepted

If your are talking about an "extension" it is in the name of the file.

However, this information is used by the OS to launch a certain application. For example, Safari/Chrome/Firefox for files ending in .html.

The application then uses the header(first few bytes) of the file to see if can display it. It may also interpret it in a way that outputs junk data. For example, if you rename a image (.jpg) file with the extension .txt, the OS will try to open the default text editor ( NotePad/TextEdit) to open it. The editor will try to interpret it as if its a text file, and will not show you an image.

You also mentioned "this page". This page is transfered by HTTP from stackoverflow to your browser. The HTTP header should mention that the data it is sending over is text/html. The browser will interpret it as HTML and render it. That said, browsers are very complex and forgiving. So, even if the header does not say what the type is, it will try to guess.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.