Bubble sort is one of the simplest sorting algorithms. It steps through the list (we refer to it as a pass), compares adjacent elements, and swaps them if they are in the wrong order. After each full pass through the array, the largest unsorted element is guaranteed to be in its correct final position. So with every pass, we need to check one fewer element. If you didn’t get the previous jumbo mumbo, no worries! The example is right below.
Let’s sort the following array from smallest to largest:

We compare each adjacent pair. Yellow = comparing, red = just swapped.
















✅ Final sorted array:

Enter up to 20 comma-separated numbers.
Bubble sort is easy to implement and understand. However, it performs poorly on large arrays/datasets. Therefore, bubble sort is usually only used in a learning context and not to solve real world problems. You can use faster algorithms like Merge Sort and Quick Sort.