So I'm using PIC16F877A for a project. In the data sheet it says that flash program memory is 8K. However my compiled hex-file is 21 KB, or so says windows vista.
When I install the hex file in to the PIC, it doesn't give any error messages. I'm a bit confused, how is this possible ?
Don't mix up hex with bin file format. The hex file format is a text file containing destination address, data, checksum etc.
See here for details: https://en.wikipedia.org/wiki/Intel_HEX
If you convert the hex file to a bin file, which is the real raw data, this would be smaller than 8kB.
You could use a hex2bin converter to find that out. But usually you want to know how much of the available rom size is consumed up by your program.
So better will be forcing your linker to generate a map file. This map file, which is a text file, contains detailed information about the used ram and rom size etc.
By default the generation of a map file is usually not activated. So check out your compilers manual how to do that. Very often this file is named xyz.map