In more detail
The signer hashes the message and transforms the hash with their private key; anyone can check the result with the matching public key (Public-key cryptography). Changing even one bit of the message breaks the signature. Signatures protect software updates, certificates, signed PDFs and DKIM email. Common algorithms are RSA, ECDSA and Ed25519; an Ed25519 signature is always 64 bytes. A valid signature proves integrity and that the holder of the private key signed, but trusting who that is needs a certificate or another way to know the public key really belongs to them.
Why it matters
Signature checks are what stop a tampered installer or a forged update from running. They only help if they are verified: a "signed" file whose signature nobody checks, or a key that has leaked, gives no protection. Keep private keys offline or in hardware where possible, and revoke them when compromised.
Example
Signing and verifying a file with an Ed25519 key in OpenSSL 3:
$ openssl genpkey -algorithm ed25519 -out ed.key
$ openssl pkey -in ed.key -pubout -out ed.pub
$ openssl pkeyutl -sign -inkey ed.key -rawin -in msg.txt -out msg.sig
$ openssl pkeyutl -verify -pubin -inkey ed.pub -rawin -in msg.txt -sigfile msg.sig
Signature Verified Successfully
Changing one character of msg.txt (1.4.2 to 1.4.3) and verifying again prints Signature Verification Failure. Make a key pair with the Key Pair Generator.
Common confusion
An Electronic signature is any electronic sign of agreement, such as a typed name or a drawn signature; a digital signature is the cryptographic mechanism, which some e-signature services use underneath.