Here is a short blog post to understand digital signatures and how public and private key works.

Digital signature has three parts to it, 1. A key generation algorithm (which creates public-private key pair) 2. Hashing /Signing algorithm. When a message and private key is given as input, this gives a hash value as an output. Variable length input fixed length output.