diff --git a/base64.h b/base64.h
index 58e2879e05b5fa4acff34682af7b2f3bc4efae48..78b0711a4170fe07deffc27b58e9517a3b9616ef 100644
--- a/base64.h
+++ b/base64.h
@@ -35,9 +35,9 @@
 /* Base64 encoding */
 
 /* Maximum length of output for base64_encode_update. NOTE: Doesn't
- * include any padding that base64_encode_final may add. */ 
-/* FIXME: Rewrite to only evaluate LENGTH once. */
-#define BASE64_ENCODE_LENGTH(length) ((length) + ((length) + 2)/3)
+ * include any padding that base64_encode_final may add. */
+/* We have at most 4 buffered bits, and a total of (4 + length * 8) bits. */
+#define BASE64_ENCODE_LENGTH(length) (((length) * 8 + 4)/6)
 
 /* Maximum lengbth of output generated by base64_encode_final. */
 #define BASE64_ENCODE_FINAL_LENGTH 3
@@ -89,9 +89,9 @@ base64_encode_group(uint8_t *dst, uint32_t group);
 
 /* Base64 decoding */
 
-/* FIXME: Think more about this definition. */
-#define BASE64_DECODE_LENGTH(length) \
-	((length) * BASE64_BINARY_BLOCK_SIZE / BASE64_TEXT_BLOCK_SIZE)
+/* Maximum length of output for base64_decode_update. */
+/* We have at most 6 buffered bits, and a total of (length + 1) * 6 bits. */
+#define BASE64_DECODE_LENGTH(length) ((((length) + 1) * 6) / 8)
 
 struct base64_decode_ctx
 {