nBits refers to the target. The target is a 256 bit number and inversely proportional to the difficulty.
You can calculate the difficulty from the target with the following formula:
difficulty = difficulty_1_target / current_target
where difficulty_1_target represents the target corresponding to the first difficulty on the network which was a 256 bit number with the leading 32 bits set to zero and the rest set to 1. Alternatively, the formula works out to:
difficulty = 2^208 * 65535 / current_target.
Back to blocks:
While we often see the block hash represented as hexadecimal numbers which include the letters from A–F for the numbers 10-15, block hashes result from SHA256d hashing. The output of SHA256 is a 256 bit number (hence the name). When miners are searching for a valid block, they create a multitude of block candidates. When one of these candidates' hash digests (interpreted as a 256 bit number) is smaller than or equal to the difficulty, the miner has found a valid block.
Okay, my question is then how is a hashoutput below that? This sounds super dumb, but I mean it has letters etc in it? Is it because we convert the hashoutput to a binary value? And then if that has a value lower than the nBit then we have solved the proof of work problem? Thanks for the help by the way! – no nein – 2017-07-27T16:00:45.530
@nonein: Hey, I've updated my answer to cover your follow-up questions. – Murch – 2017-07-27T16:41:05.480
Thanks! So in effect the A's etc are all numbers, thus making the whole thing correspond to a string of numbers? – no nein – 2017-07-27T18:04:25.720
Hexadecimal is a base sixteen number system. Each position may have values from 0-15 (as the decimal system can have values of 0-9 and the binary system can have values of 0-1). The sixteen "digits" are represented by 0-9 and A-F, where A stands for 10 and F stands for 15. – Murch – 2017-07-27T18:49:06.980
@nonein: Yeah, the letters correspond to numbers. Each character in a hexadecimal number corresponds to four characters in binary. E.g.
c45bwould translate to1100010001011011. – Murch – 2017-07-28T16:25:36.383The block is valid when one of the candidates' hash digest is lower or equal than the difficulty because the goal is to find a hash which has a specific number of zeros at the beginning? And is the target specifically set to 0x0...0(18 times)FF...F(46 times) aka the highest 64-byte hex number with 18 leading zeros? – Paul Razvan Berg – 2018-06-23T17:33:11.183