Bitcoin does not know about accounts or owners. It knows about scripts. Each output has a scriptPubKey (the lock) and each spending input provides a scriptSig or witness (the key). A node concatenates them, runs the result, and accepts the spend if it ends with TRUE.
The machine
Script is a stack-based language with about a hundred opcodes: push data, duplicate, hash, compare, check a signature, check a timelock. There are no loops and no way to write one, so every script finishes in bounded time and cannot hang a node. That limitation is deliberate; it is why Bitcoin never has "smart contract" exploits that drain the network.
Pay-to-public-key-hash, step by step
Locking script: OP_DUP OP_HASH160 <20-byte hash> OP_EQUALVERIFY OP_CHECKSIG
Unlocking script: <signature> <public key>
Execution: push the signature and key; duplicate the key; hash it; push the expected hash; verify they are equal (fail if not); check the signature against the key and the transaction. TRUE means spend.
Other standard scripts
- Multisig:
OP_2 <keyA> <keyB> <keyC> OP_3 OP_CHECKMULTISIG, usually behind a P2SH or P2WSH hash. - Timelocks:
OP_CHECKLOCKTIMEVERIFY(absolute) andOP_CHECKSEQUENCEVERIFY(relative), which Lightning and inheritance schemes use. - Hash locks: reveal a preimage whose hash matches, the basis of HTLCs.
- OP_RETURN: marks an output unspendable and carries up to 80 bytes of data.
Standardness versus consensus
Nodes relay only "standard" script forms to limit abuse; non-standard but valid scripts can still be mined. Miniscript is a modern way to compose scripts that tools can analyse and wallets can sign safely.