Library contracts in blockchain are special contracts that hold reusable code. They are deployed once and then linked to other contracts that want to use their functions. When a main contract calls a library function, the library code runs in the main contract's context, meaning it uses the main contract's storage and environment. This is done using a special call called delegatecall. The process starts by deploying the library contract, then deploying the main contract linked to the library's address. When the main contract calls a library function, the library executes and returns the result. This approach saves space and gas because the library code is not copied into every contract. If the library is not deployed or linked correctly, calls to it will fail. The example code shows a MathLib library with an add function and a Calculator contract that uses it to sum two numbers. The execution table traces deployment, linking, calling, and returning results step by step.