diff --git a/scapy/contrib/coap.py b/scapy/contrib/coap.py
index 5d03f8853831f9433c4355ff4749fd2ce0551240..fcadb6c963a374a90257475d0d4fd175f0144b12 100644
--- a/scapy/contrib/coap.py
+++ b/scapy/contrib/coap.py
@@ -178,7 +178,7 @@ class _CoAPOptsField(StrField):
                 opt_lst.append((coap_options[1][o[0]], o[1]))
             else:
                 opt_lst.append(o)
-        opt_lst.sort()
+        opt_lst.sort(key=lambda o:o[0])
 
         opts = _CoAPOpt(delta=opt_lst[0][0], opt_val=opt_lst[0][1])
         high_opt = opt_lst[0][0]
diff --git a/scapy/contrib/coap.uts b/scapy/contrib/coap.uts
index 915e5df54eb7c08b7e53206e2b4a37b52bb6c2ee..aa83c33952d525acf55c5dbfca2a69f98f8485b7 100644
--- a/scapy/contrib/coap.uts
+++ b/scapy/contrib/coap.uts
@@ -29,6 +29,12 @@ str(CoAP(options=[("Uri-Query", "query")])) == '\x40\x00\x00\x00\xd5\x02\x71\x75
 = Extended option length
 str(CoAP(options=[("Location-Path", 'x' * 280)])) == '\x40\x00\x00\x00\x8e\x0b\x00' + '\x78' * 280
 
+= Options should be ordered by option number
+str(CoAP(options=[("Uri-Query", "b"),("Uri-Path","a")])) == '\x40\x00\x00\x00\xb1\x61\x41\x62'
+
+= Options of the same type should not be reordered
+str(CoAP(options=[("Uri-Path", "b"),("Uri-Path","a")])) == '\x40\x00\x00\x00\xb1\x62\x01\x61'
+
 + Test layer binding
 = Destination port
 p = UDP()/CoAP()