Work is calculated as work = 2^256 / block_target
, as stated in the linked answer, which is the minimum hash value that counts as a valid proof-of-work (note this only changes every 2016 blocks). The source code for this is src/chain.cpp L#121. The total chain work is the sum of work for all blocks in the chain, and is calculated here: src/validation.cpp L#3713. So to visualize, the lower the block target, the more work has been done.
Example
Block 0 target: 00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
Block 1 target:
00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
Block 0: work = (2^256) / <block 0 hash> = 4.295 × 10^9
Block 1: work = (2^256) / <block 1 hash> = 4.295 × 10^9
You can see that they have both done the same amount of work. In case of a tie, the following rules apply, see https://bitcoin.stackexchange.com/a/37275/60443
- Which one was received first? (This can be different for different clients, which is why the previous rule is applied first.)
- Which one has a larger pointer address? (This is largely random, and different for different clients.)