Here is a Python implementation of bubble sort:

```python
def bubble_sort(arr):
    n = len(arr)
    for i in range(n):
        for j in range(n-i-1):
            if arr[j] > arr[j+1]:
                arr[j], arr[j+1] = arr[j+1], arr[j]
    return arr
```

In this implementation:
- `n` is the length of the input array.
- `for i in range(n)` iterates over the array from index 0 to `n-1`.
- `for j in range(n-i-1)` iterates over the array from index `0` to `n-i-1` (index `n-i`).
- `if arr[j] > arr[j+1]` checks if the current element is greater than the next element. If it is, it swaps them.
- `arr[j], arr[j+1] = arr[j+1], arr[j]` sets the current elements to the next element and the previous element.
- `return arr` returns the sorted array.