# What is the gas cost of keccak256("abc")?

According to this answer, the gas cost of `keccak256` is:

30 gas + 6 gas for each word (rounded up) for input data to a SHA3 Keccak-256 operation

I'm assuming that the size of a word is 256 bits and the size of a character is 8 bits.

Hence the gas cost `keccak256("abc")` or any other string of up to 32 characters is 36 gas units.

Is my assumption correct?

If yes, is my conclusion correct?

Thank you!

Yes, you are exactly correct, except for the empty string.

`keccak256("")` costs 30 gas.

`keccak256("0")` costs 36 gas.

`keccak256("0123456789ABCDEF0123456789ABCDEF")` still costs 36 gas.

`keccak256("0123456789ABCDEF0123456789ABCDEF_")` costs 42 gas.

These gas costs do not include costs other than the actual `KECCAK256` opcode, such as pushing the pointer and length of the input onto the stack.

• Thank you very much! BTW, no null-character issue (i.e., a string of 32 characters would cost 40 gas units)? Commented Dec 13, 2018 at 11:50
• @goodvibration No, 32 characters costs 36 gas. Solidity stores the length of the string before the actual string characters. It does not use a null terminator like C. Commented Dec 13, 2018 at 11:52