Recently, I was working on a project where I had to process some binary data. The challenge was simple: I needed to add two binary numbers in Python.
At first, I thought this would be easy, but then I realized there are multiple ways to do it. Depending on the situation, one method may be faster or easier to understand than another.
In this tutorial, I’ll show you different ways to add two binary numbers in Python. I’ll also share my firsthand experience so you can pick the method that works best for your project.
Method 1 – Use Python’s bin() and int() Functions
The easiest way to add two binary numbers in Python is to convert them into decimal, perform the addition, and then convert back to binary.
Here’s how I do it:
# Python program to add two binary numbers using bin() and int()
# Two binary numbers
binary_num1 = "1011" # 11 in decimal
binary_num2 = "1101" # 13 in decimal
# Convert to decimal and add
sum_decimal = int(binary_num1, 2) + int(binary_num2, 2)
# Convert back to binary
sum_binary = bin(sum_decimal)
# Print results
print("First Binary Number:", binary_num1)
print("Second Binary Number:", binary_num2)
print("Sum in Binary:", sum_binary[2:]) # Remove '0b' prefixOutput:
First Binary Number: 1011
Second Binary Number: 1101
Sum in Binary: 11000I executed the above example code and added the screenshot below.

This method is quick and works perfectly when you’re dealing with binary strings.
Method 2 – Add Binary Numbers Using format()
Another approach I often use is the format() function in Python. It makes the output cleaner and avoids manually slicing strings.
# Python program to add two binary numbers using format()
binary_num1 = "1110" # 14 in decimal
binary_num2 = "1010" # 10 in decimal
# Perform addition
sum_decimal = int(binary_num1, 2) + int(binary_num2, 2)
# Convert to binary using format
sum_binary = format(sum_decimal, "b")
print("Binary Sum:", sum_binary)Output:
Binary Sum: 11000I executed the above example code and added the screenshot below.

This method is more elegant and beginner-friendly.
Method 3 – Bitwise Addition (Without Using + Operator)
Sometimes, I like to challenge myself by avoiding built-in arithmetic operators. Using bitwise operators, we can add binary numbers just like a computer would at the hardware level.
# Python program to add two binary numbers using bitwise operators
def add_binary(a, b):
while b != 0:
# Carry now contains common set bits of a and b
carry = a & b
# Sum of bits where at least one is not set
a = a ^ b
# Carry is shifted by one so that adding it to a gives the required sum
b = carry << 1
return a
# Example usage
binary_num1 = int("1011", 2) # 11
binary_num2 = int("1101", 2) # 13
result = add_binary(binary_num1, binary_num2)
print("Sum in Binary:", bin(result)[2:])Output:
Sum in Binary: 11000I executed the above example code and added the screenshot below.

This method is somewhat advanced, but it’s useful if you want to understand how computers perform binary addition at the bit level.
Method 4 – Use User Input
In real-world applications, I often need to take binary numbers as input from users. Here’s a simple way to do it:
# Python program to add two binary numbers from user input
# Take binary input from user
binary_num1 = input("Enter first binary number: ")
binary_num2 = input("Enter second binary number: ")
# Convert and add
sum_decimal = int(binary_num1, 2) + int(binary_num2, 2)
# Convert back to binary
print("Sum in Binary:", bin(sum_decimal)[2:])Example Run:
Enter first binary number: 1010
Enter second binary number: 1111
Sum in Binary: 11001This method is perfect if you’re building a small tool or script for end users.
Method 5 – Use Python’s bin() with map() for Multiple Numbers
Sometimes, I need to add more than two binary numbers. Instead of repeating the process, I use map() with sum().
# Python program to add multiple binary numbers
binary_numbers = ["1010", "1101", "111"]
# Convert all to decimal and sum them
sum_decimal = sum(map(lambda x: int(x, 2), binary_numbers))
# Convert back to binary
print("Sum of all binary numbers:", bin(sum_decimal)[2:])Output:
Sum of all binary numbers: 11100This method is concise and works great when you have a list of binary numbers.
When I first started working with binary numbers in Python, I thought it would be complicated. But as you’ve seen, Python makes it simple with functions like bin(), int(), and even bitwise operators if you want to go deeper.
You don’t need to stick to just one method: pick the one that feels most natural for your project. For quick tasks, I usually go with bin() and int(). If I’m building something more advanced, I like to experiment with bitwise addition.
You may also read:
- Fix the IndexError: tuple index out of range Error in Python
- Create a Tuple from the List in Python
- Find the Length of a Tuple in Python
- Add Tuples to Lists in Python

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.